Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 171287
Collapse All | Expand All

(-)src/org/eclipse/tptp/monitoring/managedagent/internal/ManagedResourceAgentControlProvider.java (-213 / +4 lines)
Lines 23-32 Link Here
23
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.IViewPart;
24
import org.eclipse.ui.IWorkbenchPart;
24
import org.eclipse.ui.IWorkbenchPart;
25
25
26
/**
27
 * The control provider for the PI agent 
28
 * @author Ali Mehregani
29
 */
30
public class ManagedResourceAgentControlProvider extends AbstractAgentControlProvider
26
public class ManagedResourceAgentControlProvider extends AbstractAgentControlProvider
31
{	
27
{	
32
	/** The id of the contributed items */
28
	/** The id of the contributed items */
Lines 34-42 Link Here
34
	private static final String REMOVE_ITEM = "org.eclipse.tptp.monitoring.managedagent.wsdm.internal.popupMenu.remove"; //$NON-NLS-1$
30
	private static final String REMOVE_ITEM = "org.eclipse.tptp.monitoring.managedagent.wsdm.internal.popupMenu.remove"; //$NON-NLS-1$
35
	
31
	
36
	/** The agent state modifier */
32
	/** The agent state modifier */
37
	private IControlItem connectControlItem;
33
	private ManagedAgentStateModifier agentStateModifier;
38
	private IControlItem removeControlItem;
39
	private IAgentStateModifier agentStateModifier;
40
	
34
	
41
	public ManagedResourceAgentControlProvider()
35
	public ManagedResourceAgentControlProvider()
42
	{
36
	{
Lines 46-259 Link Here
46
	
40
	
47
    protected void initializeControlItems()
41
    protected void initializeControlItems()
48
	{
42
	{
49
    	addControlItem(createConnectControlItem());
43
    	//addControlItem(createConnectControlItem());
50
    	addControlItem(createRemoveControlItem());
44
    	addControlItem(createAttachControlItem());
45
    	addControlItem(createDetachControlItem());
51
	}
46
	}
52
47
53
	
54
//	public IAgentStateModifier getAgentStateModifier()
55
//	{
56
//		return null;
57
//		if (stateModifier != null)
58
//			return stateModifier;
59
//		
60
//		stateModifier = new IAgentStateModifier()
61
//		{
62
//
63
//			/**
64
//			 * Display a message that indicates that the detach option
65
//			 * has been invoked.
66
//			 */
67
//			public void detach() throws CoreException
68
//			{
69
//				showMessage("Detach option is invoked");
70
//			}
71
//
72
//			/**
73
//			 * Display a message that indicates that the attach option
74
//			 * has been invoked.
75
//			 */
76
//			public void attach() throws CoreException
77
//			{
78
//				showMessage("Attach option is invoked");
79
//			}
80
//
81
//			/**
82
//			 * Display a message that indicates that the resume option
83
//			 * has been invoked.
84
//			 */
85
//			public void startMonitoring() throws CoreException
86
//			{
87
//				showMessage("Resume option is invoked");
88
//			}
89
//
90
//			/**
91
//			 * Display a message that indicates that the pause option
92
//			 * has been invoked.
93
//			 */
94
//			public void pauseMonitoring() throws CoreException
95
//			{
96
//				showMessage("Pause option is invoked");
97
//			}
98
//
99
//			
100
//			/**
101
//			 * Returning true will always ensure that teh attach
102
//			 * option will always be enabled.
103
//			 */
104
//			public boolean canAttach()
105
//			{
106
//				return true;
107
//			}
108
//		
109
//			/**
110
//			 * Returning true will always ensure that teh attach
111
//			 * option will always be enabled.
112
//			 */
113
//			public boolean canDetach()
114
//			{
115
//				return true;
116
//			}
117
//			
118
//			/**
119
//			 * Returning true will always ensure that teh attach
120
//			 * option will always be enabled.
121
//			 */
122
//			public boolean canResume()
123
//			{
124
//				return true;
125
//			}
126
//			
127
//			/**
128
//			 * Returning true will always ensure that teh attach
129
//			 * option will always be enabled.
130
//			 */
131
//			public boolean canPause()
132
//			{
133
//				return true;
134
//			}
135
//
136
//			public void setInput(StructuredSelection input)
137
//			{		
138
//			}
139
//		
140
//			/**
141
//			 * Opens a message dialog with the message passed in.
142
//			 */
143
//			private void showMessage(String message)
144
//			{
145
//						
146
//			}
147
//		};
148
//		
149
//		return stateModifier;
150
//	}
151
    	
152
	
153
	protected IControlItem createConnectControlItem()
154
	{
155
		if (connectControlItem != null)
156
			return connectControlItem;
157
		
158
		connectControlItem = new ConnectControlItem();		
159
		return connectControlItem;
160
	}
161
	
162
	protected IControlItem createRemoveControlItem()
163
	{
164
		if (removeControlItem != null)
165
			return removeControlItem;
166
		
167
		removeControlItem = new RemoveControlItem();		
168
		return removeControlItem;
169
	}
170
	
171
	public static class ConnectControlItem extends ControlItem
172
	{
173
		//CollectObjRefAction collectObjRef;
174
		public ConnectControlItem()
175
		{
176
			super(CONNECT_ITEM, Messages.getString("ManagedResourceAgentControlProvider.MANAGED_AGENT"), Messages.getString("ManagedResourceAgentControlProvider.CONNECT.UI."), TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_DUMP)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
177
			//collectObjRef = new CollectObjRefAction();
178
			
179
			IWorkbenchPart part = UIPlugin.getActiveWorkbenchWindow().getActivePage().getActivePart();
180
			part = (part == null || !(part instanceof IViewPart)) ? part = UIPlugin.getDefault().getViewer() : part;
181
			/*if (part instanceof IViewPart)
182
				collectObjRef.init((IViewPart)part);
183
				*/
184
		}
185
		
186
		public void run()
187
		{
188
			try
189
			{
190
				/*for (Iterator agents = input.iterator(); agents.hasNext();)
191
					collectObjRef.doAction(agents.next());*/
192
			}
193
			catch (Exception e)
194
			{
195
				LauncherUtility.openMessageWithDetail(IStatus.ERROR, "", e.getMessage(), e); //$NON-NLS-1$
196
			}
197
		}
198
		
199
		
200
		public boolean isEnabled()
201
		{
202
//			if (input == null || input.size() == 0)
203
//				return false;
204
			
205
			boolean isEnable = true;
206
			/*for (Iterator agents = input.iterator(); isEnable && agents.hasNext();)
207
				isEnable = isEnable && collectObjRef.isEnabledFor(agents.next());*/
208
			return isEnable;
209
		}
210
			
211
	}
212
	
213
	
214
	public static class RemoveControlItem extends ControlItem
215
	{
216
		//private RunGCAction gcAction;
217
		public RemoveControlItem()
218
		{
219
			super(REMOVE_ITEM, CommonUITraceConstants.PROFILE_GC_GROUP, Messages.getString("ManagedResourceAgentControlProvider.REMOVE.UI."), TraceUIImages.INSTANCE.getImageDescriptor("c", TraceUIImages.IMG_GC)); //$NON-NLS-1$ //$NON-NLS-2$
220
			//gcAction = new RunGCAction();
221
			
222
			IWorkbenchPart part = UIPlugin.getActiveWorkbenchWindow().getActivePage().getActivePart();
223
			part = (part == null || !(part instanceof IViewPart)) ? part = UIPlugin.getDefault().getViewer() : part;
224
			/*if (part instanceof IViewPart)
225
				gcAction.init((IViewPart)part);
226
				*/
227
		}
228
		
229
		public void run()
230
		{
231
			try
232
			{
233
				/*for (Iterator agents = input.iterator(); agents.hasNext();)
234
					gcAction.doAction(agents.next());*/
235
			}
236
			catch (Exception e)
237
			{
238
				LauncherUtility.openMessageWithDetail(IStatus.ERROR, "", e.getMessage(), e); //$NON-NLS-1$
239
			}
240
		}
241
		
242
		
243
		public boolean isEnabled()
244
		{
245
			if (input == null || input.size() == 0)
246
				return false;
247
			
248
			boolean isEnable = true;
249
			/*for (Iterator agents = input.iterator(); isEnable && agents.hasNext();)
250
				isEnable = isEnable && gcAction.isEnabledFor(agents.next());*/
251
			return isEnable;
252
		}
253
			
254
	}
255
256
257
	public IAgentStateModifier getAgentStateModifier() {
48
	public IAgentStateModifier getAgentStateModifier() {
258
		return agentStateModifier;
49
		return agentStateModifier;
259
	}
50
	}
(-)src/org/eclipse/tptp/monitoring/managedagent/internal/ManagedAgentStateModifier.java (-9 / +106 lines)
Lines 12-33 Link Here
12
package org.eclipse.tptp.monitoring.managedagent.internal;
12
package org.eclipse.tptp.monitoring.managedagent.internal;
13
13
14
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.hyades.internal.execution.local.control.Agent;
16
import org.eclipse.hyades.internal.execution.local.control.InactiveAgentException;
17
import org.eclipse.hyades.internal.execution.local.control.InactiveProcessException;
18
import org.eclipse.hyades.loaders.util.LoadersUtils;
19
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
20
import org.eclipse.hyades.models.hierarchy.impl.TRCAgentProxyImpl;
21
import org.eclipse.hyades.trace.internal.ui.PDProjectExplorer;
22
import org.eclipse.hyades.trace.ui.ProfileEvent;
23
import org.eclipse.hyades.trace.ui.UIPlugin;
24
import org.eclipse.hyades.trace.ui.internal.util.PDCoreUtil;
15
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.StructuredSelection;
26
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier;
27
import org.eclipse.tptp.trace.ui.provisional.control.provider.IAgentStateModifier;
28
import org.eclipse.ui.IWorkbench;
29
import org.eclipse.ui.IWorkbenchPage;
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.part.ViewPart;
17
32
18
public class ManagedAgentStateModifier implements IAgentStateModifier {
33
public class ManagedAgentStateModifier implements IAgentStateModifier {
34
	TRCAgentProxy _agentProxy = null;
35
	Agent _agent = null;
36
	
37
	private static final String PROFILING_MONITORS_VIEW_ID = PDProjectExplorer.ID;
19
38
20
	public void attach() throws CoreException {
39
	public void attach() throws CoreException {
21
		System.out.println("Attach called!");
40
		try {
41
			_agent.attach();
42
		} catch (InactiveAgentException e) {
43
			// TODO Auto-generated catch block
44
			e.printStackTrace();
45
		} catch (InactiveProcessException e) {
46
			// TODO Auto-generated catch block
47
			e.printStackTrace();
48
		}
49
	}
50
	
51
	public void detach() throws CoreException {
52
		try {
53
			_agent.detach();
54
			LoadersUtils.deregisterAgentInstance(_agentProxy);
55
			//DeleteUtil.deleteAgent(_agentProxy, false, false, false, "");
56
			refreshView();
57
		} catch (Exception e) {
58
			// TODO Auto-generated catch block
59
			e.printStackTrace();
60
		}
61
	}
62
	
63
	private void refreshView(){
64
		Display d = Display.getDefault();
65
		d.asyncExec(new Runnable(){
66
			public void run(){
67
				final ProfileEvent event = UIPlugin.getDefault().getProfileEvent();
68
				event.setSource(_agent);
69
				event.setType(ProfileEvent.START_MONITOR);
70
				UIPlugin.getDefault().notifyProfileEventListener(event);
71
			}
72
		});
73
		
74
		
75
		IWorkbench workbench= UIPlugin.getDefault().getWorkbench();
76
		IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
77
		IWorkbenchPage page= window.getActivePage();
78
		ViewPart view = (ViewPart) page.findView(PROFILING_MONITORS_VIEW_ID);
22
	}
79
	}
23
80
24
	public boolean canAttach() {
81
	public boolean canAttach() {
25
		// TODO Auto-generated method stub
82
		if(_agent!=null){
83
			return !_agent.isAttached();
84
		}
26
		return false;
85
		return false;
27
	}
86
	}
28
87
29
	public boolean canDetach() {
88
	public boolean canDetach() {
30
		// TODO Auto-generated method stub
89
		if(_agent!=null){
90
			return _agent.isAttached();
91
		}
31
		return false;
92
		return false;
32
	}
93
	}
33
94
Lines 41-50 Link Here
41
		return false;
102
		return false;
42
	}
103
	}
43
104
44
	public void detach() throws CoreException {
45
		// TODO Auto-generated method stub
46
47
	}
48
105
49
	public void pauseMonitoring() throws CoreException {
106
	public void pauseMonitoring() throws CoreException {
50
		// TODO Auto-generated method stub
107
		// TODO Auto-generated method stub
Lines 52-58 Link Here
52
	}
109
	}
53
110
54
	public void setInput(StructuredSelection arg0) {
111
	public void setInput(StructuredSelection arg0) {
55
		System.out.println("Input set to "+arg0);
112
		try{
113
			_agentProxy = (TRCAgentProxyImpl) arg0.getFirstElement();
114
		}catch(Exception e){
115
			e.printStackTrace();
116
			_agentProxy = null;
117
		}
118
		if(_agentProxy!=null){
119
			_agent = getAgent(_agentProxy);
120
		}
56
121
57
	}
122
	}
58
123
Lines 60-64 Link Here
60
		// TODO Auto-generated method stub
125
		// TODO Auto-generated method stub
61
126
62
	}
127
	}
63
128
	
129
	private Agent getAgent(TRCAgentProxy proxy){
130
		Object instance = LoadersUtils.locateAgentInstance(proxy);
131
		if (instance != null && instance instanceof Agent){
132
			return (Agent) instance;
133
		}else{
134
			return null;
135
		}
136
		/*try
137
		{
138
			TRCProcessProxy process = proxy.getProcessProxy();
139
			String hostName = process.getNode().getName();
140
			Node node = PDCoreUtil.profileConnect(hostName, String
141
					.valueOf(process.getNode().getPort()));
142
			if (node == null)
143
			{
144
				return null;
145
			}
146
147
			
148
149
			if (instance == null)
150
			{
151
				instance = PDCoreUtil.getAgentInstance(hostName, process
152
						.getNode().getPort(), proxy);
153
			}
154
155
			
156
		}catch(Exception e){
157
			e.printStackTrace();
158
			return null;
159
		}*/
160
	}
64
}
161
}
(-)src/org/eclipse/tptp/monitoring/managedagent/provisional/ManagedResourceAgent.java (-3 / +9 lines)
Lines 98-106 Link Here
98
	public void setMonitored(boolean isMonitored) {	}
98
	public void setMonitored(boolean isMonitored) {	}
99
	public void setAttached(boolean isAttached) {	}
99
	public void setAttached(boolean isAttached) {	}
100
	public void startMonitoring(DataProcessor processor) throws InactiveAgentException {	}
100
	public void startMonitoring(DataProcessor processor) throws InactiveAgentException {	}
101
	public void stopMonitoring() throws InactiveAgentException {	}
101
	public void stopMonitoring() throws InactiveAgentException {	
102
	public void attach() throws InactiveAgentException, InactiveProcessException {	}
102
	}
103
	public void detach() throws InactiveAgentException, InactiveProcessException {	}
103
	public void attach() throws InactiveAgentException, InactiveProcessException {
104
		setActive(true);
105
	}
106
	public void detach() throws InactiveAgentException, InactiveProcessException {	
107
		stopMonitoring();
108
		setActive(false);
109
	}
104
	
110
	
105
	/**
111
	/**
106
	 * Get the type of agent. This returns the static generic type of the agent to differentiate it
112
	 * Get the type of agent. This returns the static generic type of the agent to differentiate it
(-)plugin.xml (-1 / +1 lines)
Lines 12-18 Link Here
12
         point="org.eclipse.hyades.trace.ui.agentDeclaration">
12
         point="org.eclipse.hyades.trace.ui.agentDeclaration">
13
      <agent
13
      <agent
14
            id="org.eclipse.tptp.monitoring.managedagent.ManagedResourceAgent"
14
            id="org.eclipse.tptp.monitoring.managedagent.ManagedResourceAgent"
15
            name="ManagedResourceAgent"
15
            name="*"
16
            type="ManagedAgent"/>
16
            type="ManagedAgent"/>
17
   </extension>
17
   </extension>
18
   <extension
18
   <extension

Return to bug 171287