|
Lines 1-5
Link Here
|
| 1 |
/********************************************************************** |
1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2007 IBM Corporation, Intel Corporation. |
2 |
* Copyright (c) 2007 2008 IBM Corporation, Intel Corporation. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 12-17
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.util.Iterator; |
13 |
import java.util.Iterator; |
| 14 |
|
14 |
|
|
|
15 |
import org.eclipse.core.commands.IHandler; |
| 15 |
import org.eclipse.core.runtime.CoreException; |
16 |
import org.eclipse.core.runtime.CoreException; |
| 16 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 17 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.IStatus; |
|
Lines 21-51
Link Here
|
| 21 |
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy; |
22 |
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy; |
| 22 |
import org.eclipse.hyades.models.hierarchy.TRCNode; |
23 |
import org.eclipse.hyades.models.hierarchy.TRCNode; |
| 23 |
import org.eclipse.hyades.trace.ui.ProfileEvent; |
24 |
import org.eclipse.hyades.trace.ui.ProfileEvent; |
| 24 |
import org.eclipse.hyades.trace.ui.internal.core.TraceUIImages; |
|
|
| 25 |
import org.eclipse.jface.dialogs.MessageDialog; |
25 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 26 |
import org.eclipse.jface.viewers.StructuredSelection; |
26 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 27 |
import org.eclipse.osgi.util.NLS; |
27 |
import org.eclipse.osgi.util.NLS; |
| 28 |
import org.eclipse.tptp.platform.common.ui.trace.internal.CommonUITraceConstants; |
|
|
| 29 |
import org.eclipse.tptp.platform.execution.client.agent.ICollector; |
28 |
import org.eclipse.tptp.platform.execution.client.agent.ICollector; |
| 30 |
import org.eclipse.tptp.platform.execution.client.core.IAgentController; |
29 |
import org.eclipse.tptp.platform.execution.client.core.IAgentController; |
| 31 |
import org.eclipse.tptp.platform.execution.exceptions.InactiveAgentException; |
30 |
import org.eclipse.tptp.platform.execution.exceptions.InactiveAgentException; |
| 32 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIMessages; |
31 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIMessages; |
| 33 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIPlugin; |
32 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIPlugin; |
| 34 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIUtility; |
33 |
import org.eclipse.tptp.platform.jvmti.client.internal.TIUtility; |
| 35 |
import org.eclipse.tptp.platform.jvmti.client.internal.actions.RunGCActionDelegate; |
|
|
| 36 |
import org.eclipse.tptp.platform.jvmti.client.internal.controlproviders.TIProcessControlProvider.TIProcessStateModifier; |
34 |
import org.eclipse.tptp.platform.jvmti.client.internal.controlproviders.TIProcessControlProvider.TIProcessStateModifier; |
| 37 |
import org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIDelegateHelper; |
35 |
import org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIDelegateHelper; |
| 38 |
import org.eclipse.tptp.platform.jvmti.client.internal.launcher.util.AgentControllerDelegate; |
36 |
import org.eclipse.tptp.platform.jvmti.client.internal.launcher.util.AgentControllerDelegate; |
| 39 |
import org.eclipse.tptp.trace.ui.internal.control.provider.application.ControlMessages; |
|
|
| 40 |
import org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherMessages; |
37 |
import org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherMessages; |
| 41 |
import org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherUtility; |
38 |
import org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherUtility; |
| 42 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.AbstractAgentControlProvider; |
39 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.AbstractAgentControlProvider; |
| 43 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.ControlItem; |
|
|
| 44 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier; |
40 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier; |
| 45 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IControlItem; |
41 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IControlItem; |
| 46 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IProcessStateModifier; |
42 |
import org.eclipse.tptp.trace.ui.provisional.control.provider.IProcessStateModifier; |
| 47 |
|
43 |
|
| 48 |
|
|
|
| 49 |
/** |
44 |
/** |
| 50 |
* This is the TI agent control provider. Its purpose is to modify the states that the TI agent |
45 |
* This is the TI agent control provider. Its purpose is to modify the states that the TI agent |
| 51 |
* can be in (e.g. Pause/Resume/Detach/Attach). |
46 |
* can be in (e.g. Pause/Resume/Detach/Attach). |
|
Lines 54-65
Link Here
|
| 54 |
*/ |
49 |
*/ |
| 55 |
public class TIAgentControlProvider extends AbstractAgentControlProvider |
50 |
public class TIAgentControlProvider extends AbstractAgentControlProvider |
| 56 |
{ |
51 |
{ |
| 57 |
|
|
|
| 58 |
/** The id of the contributed items */ |
| 59 |
private static final String RUNGC_ITEM = "org.eclipse.tptp.trace.jvmti.client.internal.popupMenu.RunGCAction"; |
| 60 |
|
| 61 |
/** The runGC item */ |
52 |
/** The runGC item */ |
| 62 |
private IControlItem runGCControlItem; |
53 |
protected static IControlItem runGCControlItem; |
|
|
54 |
private IHandler handler; |
| 63 |
|
55 |
|
| 64 |
|
56 |
|
| 65 |
protected void initializeControlItems() { |
57 |
protected void initializeControlItems() { |
|
Lines 80-124
Link Here
|
| 80 |
return runGCControlItem; |
72 |
return runGCControlItem; |
| 81 |
|
73 |
|
| 82 |
runGCControlItem = new RunGCControlItem(); |
74 |
runGCControlItem = new RunGCControlItem(); |
|
|
75 |
handler = TIAgentToolbarControlProvider.garbageCollectionControlItem.getHandler(); |
| 76 |
runGCControlItem.setHandler(handler); |
| 83 |
return runGCControlItem; |
77 |
return runGCControlItem; |
| 84 |
} |
78 |
} |
| 85 |
|
|
|
| 86 |
static class RunGCControlItem extends ControlItem { |
| 87 |
|
| 88 |
private RunGCActionDelegate gcAction; |
| 89 |
|
| 90 |
public RunGCControlItem() { |
| 91 |
super(RUNGC_ITEM, CommonUITraceConstants.PROFILE_GC_GROUP, |
| 92 |
ControlMessages.CONTROL_ITEM_GC_ACTION, |
| 93 |
TraceUIImages.INSTANCE.getImageDescriptor("c", |
| 94 |
TraceUIImages.IMG_GC)); |
| 95 |
setDisabledImageDescriptor(TraceUIImages.INSTANCE |
| 96 |
.getImageDescriptor("d", TraceUIImages.IMG_GC)); |
| 97 |
gcAction = new RunGCActionDelegate(); |
| 98 |
} |
| 99 |
|
| 100 |
public void run() { |
| 101 |
try { |
| 102 |
for (Iterator agents = input.iterator(); agents.hasNext();) |
| 103 |
gcAction.doAction(agents.next()); |
| 104 |
|
| 105 |
} catch (Exception e) { |
| 106 |
LauncherUtility.openMessageWithDetail(IStatus.ERROR, "", e |
| 107 |
.getMessage(), e); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
public boolean isEnabled() { |
| 112 |
if (input == null || input.size() == 0) |
| 113 |
return false; |
| 114 |
|
| 115 |
boolean isEnable = true; |
| 116 |
for (Iterator agents = input.iterator(); isEnable |
| 117 |
&& agents.hasNext();) |
| 118 |
isEnable = isEnable && gcAction.isEnabledFor(agents.next()); |
| 119 |
return isEnable; |
| 120 |
} |
| 121 |
} |
| 122 |
|
79 |
|
| 123 |
public IAgentStateModifier getAgentStateModifier() |
80 |
public IAgentStateModifier getAgentStateModifier() |
| 124 |
{ |
81 |
{ |
|
Lines 131-382
Link Here
|
| 131 |
return TIProcessStateModifier.getInstance(); |
88 |
return TIProcessStateModifier.getInstance(); |
| 132 |
} |
89 |
} |
| 133 |
|
90 |
|
| 134 |
|
91 |
|
| 135 |
/** |
92 |
/** |
| 136 |
* The actual state modifier for the TI agent. This is a singleton class |
93 |
* The actual state modifier for the TI agent. This is a singleton class |
| 137 |
* that should be accessed via the <code>getInstance</code> method. All public |
94 |
* that should be accessed via the <code>getInstance</code> method. All public |
| 138 |
* methods of this class are synchornized. |
95 |
* methods of this class are synchornized. |
| 139 |
* |
96 |
* |
| 140 |
* @author Ali Mehregani |
97 |
* @author Ali Mehregani |
| 141 |
*/ |
98 |
*/ |
| 142 |
public static class TIAgentStateModifier implements IAgentStateModifier |
99 |
public static class TIAgentStateModifier implements IAgentStateModifier |
| 143 |
{ |
100 |
{ |
| 144 |
/** Used for the enable action operations */ |
101 |
/** Used for the enable action operations */ |
| 145 |
private static final byte CAN_ATTACH = 0x01; |
102 |
private static final byte CAN_ATTACH = 0x01; |
| 146 |
private static final byte CAN_DETACH = 0x02; |
103 |
private static final byte CAN_DETACH = 0x02; |
| 147 |
private static final byte CAN_RESUME = 0x03; |
104 |
private static final byte CAN_RESUME = 0x03; |
| 148 |
private static final byte CAN_PAUSE = 0x04; |
105 |
private static final byte CAN_PAUSE = 0x04; |
| 149 |
|
106 |
|
| 150 |
/** Used for each action */ |
107 |
/** Used for each action */ |
| 151 |
private static final byte ATTACH = 0x05; |
108 |
private static final byte ATTACH = 0x05; |
| 152 |
private static final byte DETACH = 0x06; |
109 |
private static final byte DETACH = 0x06; |
| 153 |
private static final byte RESUME = 0x07; |
110 |
private static final byte RESUME = 0x07; |
| 154 |
private static final byte PAUSE = 0x08; |
111 |
private static final byte PAUSE = 0x08; |
| 155 |
|
112 |
|
| 156 |
/** The instance of this singleton class */ |
113 |
/** The instance of this singleton class */ |
| 157 |
private static TIAgentStateModifier agentStateModifier = new TIAgentStateModifier(); |
114 |
private static TIAgentStateModifier agentStateModifier = new TIAgentStateModifier(); |
| 158 |
|
115 |
|
| 159 |
/** The input of this state modifier */ |
116 |
/** The input of this state modifier */ |
| 160 |
private StructuredSelection input; |
117 |
private StructuredSelection input; |
| 161 |
|
118 |
|
| 162 |
/** The iterator representing the input */ |
119 |
/** The iterator representing the input */ |
| 163 |
private Iterator inputIterator; |
120 |
private Iterator inputIterator; |
| 164 |
|
121 |
|
| 165 |
/** |
122 |
/** |
| 166 |
* Limit the visibility of the constructor |
123 |
* Limit the visibility of the constructor |
| 167 |
*/ |
124 |
*/ |
| 168 |
private TIAgentStateModifier() |
125 |
private TIAgentStateModifier() |
| 169 |
{ |
126 |
{ |
| 170 |
} |
127 |
} |
| 171 |
|
128 |
|
| 172 |
|
129 |
|
| 173 |
/** |
130 |
/** |
| 174 |
* Return the only instance of this class |
131 |
* Return the only instance of this class |
| 175 |
* |
132 |
* |
| 176 |
* @return The instance of this singleton class |
133 |
* @return The instance of this singleton class |
| 177 |
*/ |
134 |
*/ |
| 178 |
public static TIAgentStateModifier getInstance() |
135 |
public static TIAgentStateModifier getInstance() |
| 179 |
{ |
136 |
{ |
| 180 |
return agentStateModifier; |
137 |
return agentStateModifier; |
| 181 |
} |
138 |
} |
| 182 |
|
139 |
|
| 183 |
|
140 |
|
| 184 |
|
141 |
|
| 185 |
private TRCAgentProxy getNextAgent() |
142 |
private TRCAgentProxy getNextAgent() |
| 186 |
{ |
143 |
{ |
| 187 |
if (inputIterator == null) |
144 |
if (inputIterator == null) |
| 188 |
return null; |
145 |
return null; |
| 189 |
|
146 |
|
| 190 |
Object object; |
147 |
Object object; |
| 191 |
while (inputIterator.hasNext()) |
148 |
while (inputIterator.hasNext()) |
| 192 |
{ |
149 |
{ |
| 193 |
object = inputIterator.next(); |
150 |
object = inputIterator.next(); |
| 194 |
if (object instanceof TRCAgentProxy) |
151 |
if (object instanceof TRCAgentProxy) |
| 195 |
return (TRCAgentProxy)object; |
152 |
return (TRCAgentProxy)object; |
| 196 |
} |
153 |
} |
| 197 |
|
154 |
|
| 198 |
return null; |
155 |
return null; |
| 199 |
} |
156 |
} |
| 200 |
|
157 |
|
| 201 |
|
158 |
|
| 202 |
public synchronized boolean canAttach() |
159 |
public synchronized boolean canAttach() |
| 203 |
{ |
160 |
{ |
| 204 |
return performCollectiveAction(CAN_ATTACH); |
161 |
return performCollectiveAction(CAN_ATTACH); |
| 205 |
} |
162 |
} |
| 206 |
|
163 |
|
| 207 |
public synchronized boolean canDetach() |
164 |
public synchronized boolean canDetach() |
| 208 |
{ |
165 |
{ |
| 209 |
return performCollectiveAction(CAN_DETACH); |
166 |
return performCollectiveAction(CAN_DETACH); |
| 210 |
} |
167 |
} |
| 211 |
|
168 |
|
| 212 |
public synchronized boolean canPause() |
169 |
public synchronized boolean canPause() |
| 213 |
{ |
170 |
{ |
| 214 |
return performCollectiveAction(CAN_PAUSE); |
171 |
return performCollectiveAction(CAN_PAUSE); |
| 215 |
} |
172 |
} |
| 216 |
|
173 |
|
| 217 |
public synchronized boolean canResume() |
174 |
public synchronized boolean canResume() |
| 218 |
{ |
175 |
{ |
| 219 |
return performCollectiveAction(CAN_RESUME); |
176 |
return performCollectiveAction(CAN_RESUME); |
| 220 |
} |
177 |
} |
| 221 |
|
178 |
|
| 222 |
public synchronized void attach() throws CoreException |
179 |
public synchronized void attach() throws CoreException |
| 223 |
{ |
180 |
{ |
| 224 |
performCollectiveAction(ATTACH); |
181 |
performCollectiveAction(ATTACH); |
| 225 |
} |
182 |
} |
| 226 |
|
183 |
|
| 227 |
public synchronized void detach() throws CoreException |
184 |
public synchronized void detach() throws CoreException |
| 228 |
{ |
185 |
{ |
| 229 |
performCollectiveAction(DETACH); |
186 |
performCollectiveAction(DETACH); |
| 230 |
} |
187 |
} |
| 231 |
|
188 |
|
| 232 |
public synchronized void pauseMonitoring() throws CoreException |
189 |
public synchronized void pauseMonitoring() throws CoreException |
| 233 |
{ |
190 |
{ |
| 234 |
performCollectiveAction(PAUSE); |
191 |
performCollectiveAction(PAUSE); |
| 235 |
} |
192 |
} |
| 236 |
|
193 |
|
| 237 |
public synchronized void startMonitoring() throws CoreException |
194 |
public synchronized void startMonitoring() throws CoreException |
| 238 |
{ |
195 |
{ |
| 239 |
performCollectiveAction(RESUME); |
196 |
performCollectiveAction(RESUME); |
| 240 |
} |
197 |
} |
| 241 |
|
198 |
|
| 242 |
public synchronized void setInput(StructuredSelection input) |
199 |
public synchronized void setInput(StructuredSelection input) |
| 243 |
{ |
200 |
{ |
| 244 |
this.input = input; |
201 |
this.input = input; |
| 245 |
} |
202 |
} |
| 246 |
|
203 |
|
| 247 |
private boolean performCollectiveAction(byte operation) |
204 |
private boolean performCollectiveAction(byte operation) |
| 248 |
{ |
205 |
{ |
| 249 |
inputIterator = (input == null ? null : input.iterator()); |
206 |
inputIterator = (input == null ? null : input.iterator()); |
| 250 |
boolean status = true; |
207 |
boolean status = true; |
| 251 |
TRCAgentProxy currentAgentProxy; |
208 |
TRCAgentProxy currentAgentProxy; |
| 252 |
boolean agentSelected = false; |
209 |
boolean agentSelected = false; |
| 253 |
|
210 |
|
| 254 |
while ((currentAgentProxy = getNextAgent()) != null) |
211 |
while ((currentAgentProxy = getNextAgent()) != null) |
| 255 |
{ |
212 |
{ |
| 256 |
agentSelected = true; |
213 |
agentSelected = true; |
| 257 |
status = status && currentAgentProxy.isActive(); |
214 |
status = status && currentAgentProxy.isActive(); |
| 258 |
switch(operation) |
215 |
switch(operation) |
| 259 |
{ |
216 |
{ |
| 260 |
case CAN_ATTACH: |
217 |
case CAN_ATTACH: |
| 261 |
status = status && !currentAgentProxy.isAttached() && !currentAgentProxy.isMonitored(); |
218 |
status = status && !currentAgentProxy.isAttached() && !currentAgentProxy.isMonitored(); |
| 262 |
break; |
219 |
break; |
| 263 |
case CAN_DETACH: |
220 |
case CAN_DETACH: |
| 264 |
status = status && currentAgentProxy.isAttached(); |
221 |
status = status && currentAgentProxy.isAttached(); |
| 265 |
break; |
222 |
break; |
| 266 |
case CAN_RESUME: |
223 |
case CAN_RESUME: |
| 267 |
status = status && currentAgentProxy.isAttached() && !currentAgentProxy.isMonitored(); |
224 |
status = status && currentAgentProxy.isAttached() && !currentAgentProxy.isMonitored(); |
| 268 |
break; |
225 |
break; |
| 269 |
case CAN_PAUSE: |
226 |
case CAN_PAUSE: |
| 270 |
status = status && currentAgentProxy.isAttached() && currentAgentProxy.isMonitored(); |
227 |
status = status && currentAgentProxy.isAttached() && currentAgentProxy.isMonitored(); |
| 271 |
break; |
228 |
break; |
| 272 |
|
229 |
|
| 273 |
default: |
230 |
default: |
| 274 |
doAction(currentAgentProxy, operation); |
231 |
doAction(currentAgentProxy, operation); |
| 275 |
break; |
232 |
break; |
| 276 |
} |
233 |
} |
| 277 |
} |
234 |
} |
| 278 |
|
235 |
|
| 279 |
return status && agentSelected; |
236 |
return status && agentSelected; |
| 280 |
} |
237 |
} |
| 281 |
|
238 |
|
| 282 |
|
239 |
|
| 283 |
private void doAction(TRCAgentProxy agentProxy, byte operation) |
240 |
private void doAction(TRCAgentProxy agentProxy, byte operation) |
| 284 |
{ |
241 |
{ |
| 285 |
agentProxy.setMonitored(operation == RESUME); |
242 |
agentProxy.setMonitored(operation == RESUME); |
| 286 |
agentProxy.setAttached(!(operation == DETACH)); |
243 |
agentProxy.setAttached(!(operation == DETACH)); |
| 287 |
agentProxy.setActive(true); |
244 |
agentProxy.setActive(true); |
| 288 |
|
245 |
|
| 289 |
/* Get the TI execution agent that corresponds to the agent proxy */ |
246 |
/* Get the TI execution agent that corresponds to the agent proxy */ |
| 290 |
TRCNode trcNode = agentProxy.getProcessProxy().getNode(); |
247 |
TRCNode trcNode = agentProxy.getProcessProxy().getNode(); |
| 291 |
IAgentController agentController = null; |
248 |
IAgentController agentController = null; |
| 292 |
try |
249 |
try |
| 293 |
{ |
250 |
{ |
| 294 |
agentController = AgentControllerDelegate.getInstance().getConnection(trcNode.getName(), trcNode.getPort()); |
251 |
agentController = AgentControllerDelegate.getInstance().getConnection(trcNode.getName(), trcNode.getPort()); |
| 295 |
} |
252 |
} |
| 296 |
catch (Exception e) |
253 |
catch (Exception e) |
| 297 |
{ |
254 |
{ |
| 298 |
LauncherUtility.openErrorWithDetail(LauncherMessages.LAUNCHER_COMMON_ERROR_TITLE, NLS.bind(TIMessages.ERROR_TI_AC_UNAVAILABLE, String.valueOf(trcNode.getPort())), e); |
255 |
LauncherUtility.openErrorWithDetail(LauncherMessages.LAUNCHER_COMMON_ERROR_TITLE, NLS.bind(TIMessages.ERROR_TI_AC_UNAVAILABLE, String.valueOf(trcNode.getPort())), e); |
| 299 |
} |
256 |
} |
| 300 |
ICollector tiAgent = null; |
257 |
ICollector tiAgent = null; |
| 301 |
if (agentController != null) |
258 |
if (agentController != null) |
| 302 |
tiAgent = TIDelegateHelper.locateTIAgent(agentController, agentProxy.getProcessProxy().getPid()); |
259 |
tiAgent = TIDelegateHelper.locateTIAgent(agentController, agentProxy.getProcessProxy().getPid()); |
| 303 |
|
260 |
|
| 304 |
/* If in case the agent was not found, then terminate it and show a message */ |
261 |
/* If in case the agent was not found, then terminate it and show a message */ |
| 305 |
if (tiAgent == null) |
262 |
if (tiAgent == null) |
| 306 |
{ |
263 |
{ |
| 307 |
TIUtility.terminateAgentProxy(agentProxy, true); |
264 |
TIUtility.terminateAgentProxy(agentProxy, true); |
| 308 |
|
265 |
|
| 309 |
MessageDialog.openWarning( |
266 |
MessageDialog.openWarning( |
| 310 |
TIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), |
267 |
TIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 311 |
LauncherMessages.LAUNCHER_COMMON_WARNING_TITLE, |
268 |
LauncherMessages.LAUNCHER_COMMON_WARNING_TITLE, |
| 312 |
TIMessages.ERROR_TI_AGENT_INACTIVE); |
269 |
TIMessages.ERROR_TI_AGENT_INACTIVE); |
| 313 |
} |
270 |
} |
| 314 |
/* Otherwise perform the requested operation */ |
271 |
/* Otherwise perform the requested operation */ |
| 315 |
else |
272 |
else |
| 316 |
{ |
273 |
{ |
| 317 |
switch(operation) |
274 |
switch(operation) |
| 318 |
{ |
275 |
{ |
| 319 |
case ATTACH: |
276 |
case ATTACH: |
| 320 |
if (tiAgent != null) |
277 |
if (tiAgent != null) |
| 321 |
{ |
278 |
{ |
| 322 |
final ICollector ctiAgent = tiAgent; |
279 |
final ICollector ctiAgent = tiAgent; |
| 323 |
final TRCAgentProxy cagentProxy = agentProxy; |
280 |
final TRCAgentProxy cagentProxy = agentProxy; |
| 324 |
final IAgentController cagentController = agentController; |
281 |
final IAgentController cagentController = agentController; |
| 325 |
/* We need to terminate the current agent proxy and create a new one for the attach */ |
282 |
/* We need to terminate the current agent proxy and create a new one for the attach */ |
| 326 |
TIUtility.terminateAgentProxy(agentProxy, false); |
283 |
TIUtility.terminateAgentProxy(agentProxy, false); |
| 327 |
new Job(TIMessages.TASK_CONNECTING_TO_AGENT) { |
284 |
new Job(TIMessages.TASK_CONNECTING_TO_AGENT) { |
| 328 |
protected IStatus run(IProgressMonitor monitor) { |
285 |
protected IStatus run(IProgressMonitor monitor) { |
| 329 |
TIDelegateHelper.getInstance().attachToAgent( |
286 |
TIDelegateHelper.getInstance().attachToAgent( |
| 330 |
cagentController, cagentProxy, |
287 |
cagentController, cagentProxy, |
| 331 |
ctiAgent.getProcess(), |
288 |
ctiAgent.getProcess(), |
| 332 |
new NullProgressMonitor()); |
289 |
new NullProgressMonitor()); |
| 333 |
TIDelegateHelper.getInstance().startPolling( |
290 |
TIDelegateHelper.getInstance().startPolling( |
| 334 |
ctiAgent); |
291 |
ctiAgent); |
| 335 |
return Status.OK_STATUS; |
292 |
return Status.OK_STATUS; |
| 336 |
} |
293 |
} |
| 337 |
}.schedule(); |
294 |
}.schedule(); |
| 338 |
} |
295 |
} |
| 339 |
|
296 |
|
| 340 |
break; |
297 |
break; |
| 341 |
case DETACH: |
298 |
case DETACH: |
| 342 |
TIUtility.closeFileStream(agentProxy); |
299 |
TIUtility.closeFileStream(agentProxy); |
| 343 |
LauncherUtility.sendProfileEvent(ProfileEvent.DETACH, agentProxy); |
300 |
LauncherUtility.sendProfileEvent(ProfileEvent.DETACH, agentProxy); |
| 344 |
if (tiAgent != null) |
301 |
if (tiAgent != null) |
| 345 |
{ |
302 |
{ |
| 346 |
tiAgent.stop(); |
303 |
tiAgent.stop(); |
| 347 |
tiAgent.cancel(); |
304 |
tiAgent.cancel(); |
| 348 |
try |
305 |
try |
| 349 |
{ |
306 |
{ |
| 350 |
//Wait for a little time before stop monitoring. Some data may still be flushed |
307 |
//Wait for a little time before stop monitoring. Some data may still be flushed |
| 351 |
Thread.sleep(500); |
308 |
Thread.sleep(500); |
| 352 |
tiAgent.stopMonitoring(); |
309 |
tiAgent.stopMonitoring(); |
| 353 |
} |
310 |
} |
| 354 |
catch (InactiveAgentException e) |
311 |
catch (InactiveAgentException e) |
| 355 |
{ |
312 |
{ |
| 356 |
} |
313 |
} |
| 357 |
catch(Exception e) |
314 |
catch(Exception e) |
| 358 |
{ |
315 |
{ |
| 359 |
} |
316 |
} |
| 360 |
} |
317 |
} |
| 361 |
|
318 |
|
| 362 |
break; |
319 |
break; |
| 363 |
case RESUME: |
320 |
case RESUME: |
| 364 |
LauncherUtility.sendProfileEvent(ProfileEvent.START_MONITOR, agentProxy); |
321 |
LauncherUtility.sendProfileEvent(ProfileEvent.START_MONITOR, agentProxy); |
| 365 |
if (tiAgent != null) |
322 |
if (tiAgent != null) |
| 366 |
tiAgent.resume(); |
323 |
tiAgent.resume(); |
| 367 |
break; |
324 |
break; |
| 368 |
case PAUSE: |
325 |
case PAUSE: |
| 369 |
LauncherUtility.sendProfileEvent(ProfileEvent.STOP_MONITOR, agentProxy); |
326 |
LauncherUtility.sendProfileEvent(ProfileEvent.STOP_MONITOR, agentProxy); |
| 370 |
if (tiAgent != null) |
327 |
if (tiAgent != null) |
| 371 |
tiAgent.pause(); |
328 |
tiAgent.pause(); |
| 372 |
break; |
329 |
break; |
| 373 |
|
330 |
|
| 374 |
default: |
331 |
default: |
| 375 |
break; |
332 |
break; |
| 376 |
} |
333 |
} |
| 377 |
|
334 |
} |
| 378 |
} |
335 |
} |
| 379 |
|
336 |
} |
| 380 |
} |
|
|
| 381 |
} |
| 382 |
} |
337 |
} |