1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2014 Oracle and/or its affiliates.  All rights reserved.
5  *
6  */
7 package com.sleepycat.je.rep;
8 
9 import java.util.concurrent.TimeUnit;
10 import java.util.logging.Logger;
11 
12 import com.sleepycat.je.EnvironmentFailureException;
13 import com.sleepycat.je.dbi.EnvironmentFailureReason;
14 import com.sleepycat.je.rep.impl.node.RepNode;
15 import com.sleepycat.je.utilint.LoggerUtils;
16 import com.sleepycat.je.utilint.VLSN;
17 /**
18  * Thrown when an attempt is made to access an environment  that was
19  * shutdown by the Master as a result of a call to
20  * {@link ReplicatedEnvironment#shutdownGroup(long, TimeUnit)}.
21  */
22 public class GroupShutdownException extends EnvironmentFailureException {
23     private static final long serialVersionUID = 1;
24 
25     /* The time that the shutdown was initiated on the master. */
26     private final long shutdownTimeMs;
27 
28     /* The master node that initiated the shutdown. */
29     private final String masterNodeName;
30 
31     /* The VLSN at the time of shutdown */
32     private final VLSN shutdownVLSN;
33 
34     /**
35      * For internal use only.
36      * @hidden
37      */
GroupShutdownException(Logger logger, RepNode repNode, long shutdownTimeMs)38     public GroupShutdownException(Logger logger,
39                                   RepNode repNode,
40                                   long shutdownTimeMs) {
41         super(repNode.getRepImpl(),
42               EnvironmentFailureReason.SHUTDOWN_REQUESTED,
43               String.format("Master:%s, initiated shutdown at %1tc.",
44                             repNode.getMasterStatus().getNodeMasterNameId().
45                                 getName(),
46                             shutdownTimeMs));
47 
48         shutdownVLSN = repNode.getVLSNIndex().getRange().getLast();
49         masterNodeName =
50             repNode.getMasterStatus().getNodeMasterNameId().getName();
51         this.shutdownTimeMs = shutdownTimeMs;
52 
53         LoggerUtils.warning(logger, repNode.getRepImpl(),
54                             "Explicit shutdown request from Master:" +
55                             masterNodeName);
56     }
57 
58     /**
59      * For internal use only.
60      * @hidden
61      */
GroupShutdownException(String message, GroupShutdownException shutdownException)62     private GroupShutdownException(String message,
63                                    GroupShutdownException shutdownException) {
64         super(message, shutdownException);
65         shutdownVLSN = shutdownException.shutdownVLSN;
66         shutdownTimeMs = shutdownException.shutdownTimeMs;
67         masterNodeName =  shutdownException.masterNodeName;
68     }
69 
70     /**
71      * For internal use only.
72      * @hidden
73      */
74     @Override
wrapSelf(String msg)75     public  GroupShutdownException wrapSelf(String msg) {
76         return new GroupShutdownException(msg, this);
77     }
78 
79     /**
80      * For internal use only.
81      *
82      * Returns the shutdownVLSN, if it was available, at the time of the
83      * exception
84      *
85      * @hidden
86      */
getShutdownVLSN()87     public VLSN getShutdownVLSN() {
88         return shutdownVLSN;
89     }
90 }
91