1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 package com.zeroc.IceGridGUI.LiveDeployment;
6 
7 import javax.swing.SwingUtilities;
8 import javax.swing.JOptionPane;
9 
10 import com.zeroc.IceGridGUI.*;
11 
12 public abstract class TreeNode extends TreeNodeBase
13 {
getEditor()14     public abstract Editor getEditor();
15 
TreeNode(TreeNode parent, String id)16     TreeNode(TreeNode parent, String id)
17     {
18         super(parent, id);
19     }
20 
getRoot()21     Root getRoot()
22     {
23         assert _parent != null;
24         return ((TreeNode)_parent).getRoot();
25     }
26 
27     //
28     // Actions
29     //
30     public static final int START = 0;
31     public static final int STOP = 1;
32     public static final int ENABLE = 2;
33     public static final int DISABLE = 3;
34 
35     public static final int SIGHUP = 4;
36     public static final int SIGINT = 5;
37     public static final int SIGQUIT = 6;
38     public static final int SIGKILL = 7;
39     public static final int SIGUSR1 = 8;
40     public static final int SIGUSR2 = 9;
41     public static final int SIGTERM = 10;
42 
43     public static final int WRITE_MESSAGE = 11;
44 
45     public static final int RETRIEVE_ICE_LOG = 12;
46     public static final int RETRIEVE_STDOUT = 13;
47     public static final int RETRIEVE_STDERR = 14;
48     public static final int RETRIEVE_LOG_FILE = 15;
49 
50     public static final int SHUTDOWN_NODE = 16;
51     public static final int SHUTDOWN_REGISTRY = 17;
52 
53     public static final int PATCH_SERVER = 18;
54 
55     public static final int ADD_OBJECT = 19;
56 
57     public static final int OPEN_DEFINITION = 20;
58 
59     public static final int ENABLE_METRICS_VIEW = 21;
60     public static final int DISABLE_METRICS_VIEW = 22;
61 
62     public static final int START_ALL_SERVERS = 23;
63     public static final int STOP_ALL_SERVERS = 24;
64 
65     public static final int ACTION_COUNT = 25;
66 
getAvailableActions()67     public boolean[] getAvailableActions()
68     {
69         return new boolean[ACTION_COUNT];
70     }
71 
start()72     public void start()
73     {
74         assert false;
75     }
stop()76     public void stop()
77     {
78         assert false;
79     }
enable()80     public void enable()
81     {
82         assert false;
83     }
disable()84     public void disable()
85     {
86         assert false;
87     }
writeMessage()88     public void writeMessage()
89     {
90         assert false;
91     }
retrieveIceLog()92     public void retrieveIceLog()
93     {
94         assert false;
95     }
retrieveOutput(boolean stdout)96     public void retrieveOutput(boolean stdout)
97     {
98         assert false;
99     }
retrieveLogFile()100     public void retrieveLogFile()
101     {
102         assert false;
103     }
signal(String s)104     public void signal(String s)
105     {
106         assert false;
107     }
shutdownNode()108     public void shutdownNode()
109     {
110         assert false;
111     }
shutdownRegistry()112     public void shutdownRegistry()
113     {
114         assert false;
115     }
patchServer()116     public void patchServer()
117     {
118         assert false;
119     }
addObject()120     public void addObject()
121     {
122         assert false;
123     }
openDefinition()124     public void openDefinition()
125     {
126         assert false;
127     }
enableMetricsView(boolean enabled)128     public void enableMetricsView(boolean enabled)
129     {
130         assert false;
131     }
startAllServers()132     public void startAllServers()
133     {
134         assert false;
135     }
stopAllServers()136     public void stopAllServers()
137     {
138         assert false;
139     }
clearShowIceLogDialog()140     public void clearShowIceLogDialog()
141     {
142         assert false;
143     }
144 
145     //
146     // Helpers
147     //
amiComplete(final String prefix, final String title, final Throwable ex)148     protected void amiComplete(final String prefix, final String title, final Throwable ex)
149     {
150         if(ex == null)
151         {
152             amiSuccess(prefix);
153         }
154         else if(ex instanceof com.zeroc.Ice.UserException)
155         {
156             amiFailure(prefix, title, (com.zeroc.Ice.UserException)ex);
157         }
158         else
159         {
160             amiFailure(prefix, title, ex.toString());
161         }
162     }
163 
amiSuccess(final String prefix)164     protected void amiSuccess(final String prefix)
165     {
166         SwingUtilities.invokeLater(() -> success(prefix));
167     }
168 
amiSuccess(final String prefix, final String detail)169     protected void amiSuccess(final String prefix, final String detail)
170     {
171         SwingUtilities.invokeLater(() -> success(prefix, detail));
172     }
173 
amiFailure(String prefix, String title, Throwable e)174     protected void amiFailure(String prefix, String title, Throwable e)
175     {
176         if(e instanceof com.zeroc.IceGrid.ServerNotExistException)
177         {
178             com.zeroc.IceGrid.ServerNotExistException sne = (com.zeroc.IceGrid.ServerNotExistException)e;
179 
180             amiFailure(prefix, title, "Server '" + sne.id + "' was not registered with the IceGrid Registry");
181         }
182         else if(e instanceof com.zeroc.IceGrid.ServerStartException)
183         {
184             com.zeroc.IceGrid.ServerStartException ste = (com.zeroc.IceGrid.ServerStartException)e;
185             amiFailure(prefix, title, "Server '" + ste.id + "' did not start: " + ste.reason);
186         }
187         else if(e instanceof com.zeroc.IceGrid.ApplicationNotExistException)
188         {
189             amiFailure(prefix, title, "This application was not registered with the IceGrid Registry");
190         }
191         else if(e instanceof com.zeroc.IceGrid.PatchException)
192         {
193             com.zeroc.IceGrid.PatchException pe = (com.zeroc.IceGrid.PatchException)e;
194 
195             String message = "";
196             for(String s : pe.reasons)
197             {
198                 if(message.length() > 0)
199                 {
200                     message += "\n";
201                 }
202                 message += s;
203             }
204             amiFailure(prefix, title, message);
205         }
206         else if(e instanceof com.zeroc.IceGrid.NodeNotExistException)
207         {
208             com.zeroc.IceGrid.NodeNotExistException nnee = (com.zeroc.IceGrid.NodeNotExistException)e;
209 
210             amiFailure(prefix, title, "Node '" + nnee.name + " 'was not registered with the IceGrid Registry.");
211         }
212         else if(e instanceof com.zeroc.IceGrid.NodeUnreachableException)
213         {
214             com.zeroc.IceGrid.NodeUnreachableException nue = (com.zeroc.IceGrid.NodeUnreachableException)e;
215             amiFailure(prefix, title, "Node '" + nue.name + "' is unreachable: " + nue.reason);
216         }
217         else if(e instanceof com.zeroc.IceGrid.DeploymentException)
218         {
219             com.zeroc.IceGrid.DeploymentException de = (com.zeroc.IceGrid.DeploymentException)e;
220             amiFailure(prefix, title, "Deployment exception: " + de.reason);
221         }
222         else if(e instanceof com.zeroc.Ice.ObjectNotExistException)
223         {
224             SwingUtilities.invokeLater(() -> { getCoordinator().getSessionKeeper().sessionLost(); });
225         }
226         else
227         {
228             amiFailure(prefix, title, title + ":\n" + e.toString());
229         }
230     }
231 
amiFailure(final String prefix, final String title, final String message)232     protected void amiFailure(final String prefix, final String title, final String message)
233     {
234         SwingUtilities.invokeLater(() -> failure(prefix, title, message));
235     }
236 
failure(String prefix, String title, String message)237     protected void failure(String prefix, String title, String message)
238     {
239         getCoordinator().getStatusBar().setText(prefix + " failed!");
240 
241         JOptionPane.showMessageDialog(
242             getCoordinator().getMainFrame(),
243             message,
244             title,
245             JOptionPane.ERROR_MESSAGE);
246     }
247 
success(String prefix, String detail)248     protected void success(String prefix, String detail)
249     {
250         getCoordinator().getStatusBar().setText(prefix + " done (" + detail + ").");
251     }
252 
success(String prefix)253     protected void success(String prefix)
254     {
255         getCoordinator().getStatusBar().setText(prefix + " done.");
256     }
257 
reparent(TreeNode newParent)258     void reparent(TreeNode newParent)
259     {
260         assert newParent != null;
261         _parent = newParent;
262     }
263 }
264