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 136985
Collapse All | Expand All

(-).classpath (+1 lines)
Lines 7-12 Link Here
7
	<classpathentry kind="src" path="src-automation-client"/>
7
	<classpathentry kind="src" path="src-automation-client"/>
8
	<classpathentry kind="src" path="src-automation-core"/>
8
	<classpathentry kind="src" path="src-automation-core"/>
9
	<classpathentry kind="src" path="src-automation-server"/>
9
	<classpathentry kind="src" path="src-automation-server"/>
10
	<classpathentry kind="src" path="src-local-public"/>
10
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
11
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
11
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
12
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
12
		<accessrules>
13
		<accessrules>
(-)build.properties (-1 / +2 lines)
Lines 25-31 Link Here
25
                     config.jar
25
                     config.jar
26
source.hexcore.jar = src-core/
26
source.hexcore.jar = src-core/
27
output.hexcore.jar = bin/
27
output.hexcore.jar = bin/
28
source.hexl.jar = src-local/
28
source.hexl.jar = src-local/,\
29
                  src-local-public/
29
output.hexl.jar = bin/
30
output.hexl.jar = bin/
30
source.hexr.jar = src-remote/
31
source.hexr.jar = src-remote/
31
output.hexr.jar = bin/
32
output.hexr.jar = bin/
(-)src-local-public/org/eclipse/hyades/execution/local/common/PropertyListCommand.java (+111 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: PropertyListCommand.java,v 1.6 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.util.Vector;
16
17
public class PropertyListCommand extends CommandElement implements Constants {
18
	private int size = 0;
19
	private Vector names = new Vector();
20
	private Vector types = new Vector();
21
	private Vector values = new Vector();
22
23
	public PropertyListCommand() {
24
		super();
25
		_tag = RA_PROPERTY_LIST;
26
	}
27
28
	public int getPropertyListLength() {
29
		return size;
30
	}
31
32
	public SetNVPairCommand[] getPropertyListValues() {
33
		SetNVPairCommand[] results = new SetNVPairCommand[size];
34
		for (int i = 0; i < size; i++) {
35
			results[i] = new SetNVPairCommand();
36
			results[i].setName(((RAString) names.elementAt(i)).getData());
37
			results[i].setType(((RAString) types.elementAt(i)).getData());
38
			results[i].setValue(((RAString) values.elementAt(i)).getData());
39
		}
40
		return results;
41
	}
42
43
	public void addPropertyListValue(String name, String type, String value) {
44
		RAString rName = new RAString(name);
45
		RAString rType = new RAString(type);
46
		RAString rValue = new RAString(value);
47
48
		names.add(rName);
49
		types.add(rType);
50
		values.add(rValue);
51
52
		/*
53
		 * Bug 116585: PropertyListCommand does not work for IAC
54
		 */
55
		size++;
56
	}
57
58
	public int readFromBuffer(byte[] buffer, int offset) {
59
		int current = offset;
60
61
		current = super.readFromBuffer(buffer, current);
62
63
		// Read the number of entries
64
		size = (int) Message.readRALongFromBuffer(buffer, current);
65
		current += sizeofLong;
66
67
		// Read the name, type, value entries
68
		for (int i = 0; i < size; i++) {
69
			RAString name = new RAString("");
70
			RAString type = new RAString("");
71
			RAString value = new RAString("");
72
			current = Message.readRAStringFromBuffer(buffer, current, name);
73
			current = Message.readRAStringFromBuffer(buffer, current, type);
74
			current = Message.readRAStringFromBuffer(buffer, current, value);
75
			names.addElement(name);
76
			types.addElement(type);
77
			values.addElement(value);
78
		}
79
80
		return current;
81
	}
82
83
	public int writeToBuffer(byte[] buffer, int offset) {
84
		int current = offset;
85
86
		current = super.writeToBuffer(buffer, current);
87
88
		/* Names */
89
		current = Message.writeRALongToBuffer(buffer, current, size);
90
		for (int i = 0; i < size; i++) {
91
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) names.elementAt(i)));
92
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) types.elementAt(i)));
93
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) values.elementAt(i)));
94
		}
95
96
		return current;
97
	}
98
99
	public int getSize() {
100
		int size = super.getSize();
101
102
		size += sizeofLong; // entry size
103
		for (int i = 0; i < size; i++) {
104
			size += ((RAString) names.elementAt(i)).getSize();
105
			size += ((RAString) types.elementAt(i)).getSize();
106
			size += ((RAString) values.elementAt(i)).getSize();
107
		}
108
109
		return size;
110
	}
111
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AcknowledgementMessage.java (+39 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AcknowledgementMessage.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AcknowledgementMessage extends Message {
16
17
	/**
18
	 * AcknowledgementMessage constructor comment.
19
	 */
20
	public AcknowledgementMessage() {
21
		super();
22
		_type = RA_ACKNOWLEDGEMENT_MESSAGE;
23
	}
24
25
	/**
26
	 * readFromBuffer method comment.
27
	 */
28
	public int readFromBuffer(byte[] buffer, int length) {
29
		return super.readFromBuffer(buffer, length);
30
	}
31
32
	/**
33
	 * writeToBuffer method comment.
34
	 */
35
	public int writeToBuffer(byte[] buffer, int offset) {
36
		return super.writeToBuffer(buffer, offset);
37
	}
38
39
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Agent.java (+162 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Agent.java,v 1.4 2005/09/27 20:31:58 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import org.eclipse.hyades.execution.local.common.CustomCommand;
16
import org.eclipse.hyades.execution.local.common.DataProcessor;
17
18
public interface Agent {
19
20
	/**
21
	 * Add a listener that will inform you when this Agent becomes active/inactive.
22
	 * 
23
	 * @see AgentListener
24
	 */
25
	void addAgentListener(AgentListener listener);
26
27
	/**
28
	 * Remove a listener previously added with addAgentListener.
29
	 * 
30
	 * @see AgentListener
31
	 */
32
	void removeAgentListener(AgentListener listener);
33
34
	/**
35
	 * Get the process which this agent is a member of.
36
	 * 
37
	 * @return the Process if it exists, null otherwise.
38
	 */
39
	Process getProcess();
40
41
	void setProcess(Process p);
42
43
	/**
44
	 * If autoAttach is set, this is like registering an interest in this agent. It may not exist yet within the process, but you want to be attached to the agent as soon as it becomes active.
45
	 */
46
	boolean isAutoAttach();
47
48
	void setAutoAttach(boolean auto);
49
50
	/**
51
	 * Attach to the agent.
52
	 */
53
	void attach() throws InactiveAgentException, InactiveProcessException;
54
55
	/**
56
	 * Detach from the agent.
57
	 */
58
	void detach() throws InactiveAgentException, InactiveProcessException;
59
60
	/**
61
	 * Retrieve the type name of this agent.
62
	 * 
63
	 * @return the type of the agent if known, null otherwise.
64
	 */
65
	String getType();
66
67
	void setType(String type);
68
69
	/**
70
	 * Retrieve the name of this agent.
71
	 * 
72
	 * @return the name of the agent if known, null otherwise.
73
	 */
74
	String getName();
75
76
	void setName(String name);
77
78
	/**
79
	 * Retrieve the UUID of this agent.
80
	 * 
81
	 * @return the uuid of the agent if it is known, null otherwise.
82
	 */
83
	String getUUID();
84
85
	void setUUID(String uuid);
86
87
	/**
88
	 * Determine whether this agent is currently active.
89
	 */
90
	boolean isActive();
91
92
	void setActive(boolean isActive);
93
94
	/**
95
	 * Determine if this agent is currently being monitored.
96
	 */
97
	boolean isMonitored();
98
99
	void setMonitored(boolean isMonitored);
100
101
	/**
102
	 * Determine is this agent is currently attached to a client.
103
	 */
104
	boolean isAttached();
105
106
	boolean isAttached(boolean remote); // Bug 54376
107
108
	void setAttached(boolean isAttached);
109
110
	/**
111
	 * Start monitoring the data output of this agent using the specified DataProcessor. You must be attached to the agent before you can start monitoring it.
112
	 */
113
	void startMonitoring(DataProcessor processor) throws InactiveAgentException;
114
115
	/**
116
	 * Stop monitoring this agent.
117
	 */
118
	void stopMonitoring() throws InactiveAgentException;
119
120
	/**
121
	 * Set the configuration for the agent.
122
	 */
123
	void setConfiguration(AgentConfiguration config);
124
125
	/**
126
	 * Get the configuration object for this agent.
127
	 * 
128
	 * @return the AgentConfiguration if it exists, null otherwise.
129
	 */
130
	AgentConfiguration getConfiguration();
131
132
	/**
133
	 * Publish's the AgentConfiguration to an active agent
134
	 */
135
	void publishConfiguration() throws InactiveAgentException;
136
137
	/**
138
	 * Send a custom command to the agent for processing.
139
	 */
140
	void invokeCustomCommand(CustomCommand command) throws InactiveAgentException;
141
142
	/**
143
	 * Determine if this agent is sending data to a profiling file
144
	 */
145
	public boolean isToProfileFile();
146
147
	/**
148
	 * Get the fully quality path of profiling file
149
	 * 
150
	 * @return String
151
	 */
152
	public String getProfileFile();
153
154
	/**
155
	 * Set the fully quality path of profiling file
156
	 * 
157
	 * @param _profileFile
158
	 *            The _profileFile to set
159
	 */
160
	public void setProfileFile(String _profileFile);
161
162
}
(-)src-local-public/org/eclipse/hyades/execution/security/UntrustedAgentControllerException.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: UntrustedAgentControllerException.java,v 1.4 2005/09/13 16:46:21 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import org.eclipse.hyades.execution.local.control.AgentControllerUnavailableException;
16
17
public class UntrustedAgentControllerException extends AgentControllerUnavailableException {
18
19
	private static final long serialVersionUID = 3690196538207122739L;
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/CommandElement.java (+98 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CommandElement.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public abstract class CommandElement implements Constants {
16
17
	protected long _tag = 0;
18
	protected long _context = 0;
19
20
	public CommandElement() {
21
		super();
22
	}
23
24
	/**
25
	 * Return the context of this command element
26
	 * 
27
	 * @return context
28
	 */
29
	public long getContext() {
30
		return _context;
31
	}
32
33
	/**
34
	 * Return the size of this command in number of bytes
35
	 * 
36
	 * @return size
37
	 */
38
	public int getSize() {
39
		return 2 * sizeofLong;
40
	}
41
42
	/**
43
	 * Return the command tag
44
	 * 
45
	 * @return tag
46
	 */
47
	public long getTag() {
48
		return _tag;
49
	}
50
51
	/**
52
	 * Construct the command by reading the buffer
53
	 * 
54
	 * @param buffer
55
	 *            Buffer containing serialized command
56
	 * @param offset
57
	 *            Start position for reading
58
	 * @return
59
	 */
60
	public int readFromBuffer(byte[] buffer, int offset) {
61
		/*
62
		 * Do not need to read the tag since it is already read before coming in
63
		 * here
64
		 */
65
		int current = offset;
66
		_context = Message.readRALongFromBuffer(buffer, current);
67
		current += sizeofLong;
68
		return current;
69
	}
70
71
	/**
72
	 * Set the command's context
73
	 * 
74
	 * @param context
75
	 */
76
	public void setContext(long context) {
77
		_context = context;
78
	}
79
80
	/**
81
	 * Serialize the command into the byte buffer
82
	 * 
83
	 * @param buffer
84
	 *            Buffer containing serialized command
85
	 * @param offset
86
	 *            Start position for reading
87
	 * @return
88
	 */
89
	public int writeToBuffer(byte[] buffer, int offset) {
90
		int current = offset;
91
92
		current = Message.writeRALongToBuffer(buffer, current, _tag);
93
		current = Message.writeRALongToBuffer(buffer, current, _context);
94
95
		return current;
96
	}
97
98
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/NodeFactory.java (+212 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: NodeFactory.java,v 1.5 2006/11/07 00:30:59 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.net.InetAddress;
16
import java.net.UnknownHostException;
17
import java.security.Principal;
18
import java.util.Hashtable;
19
20
import org.eclipse.hyades.execution.security.DuplicateUserException;
21
import org.eclipse.hyades.execution.security.User;
22
23
/**
24
 * A factory for creating Nodes. Nodes can be specified by either name or InetAddress. Each Node is treated as a singleton and attempts to create a Node that already exists will return the same Node instance that already existed.
25
 */
26
public class NodeFactory {
27
	private static String _hostname = "localhost";
28
	private static Hashtable _servers = new Hashtable();
29
30
	// static {
31
	// try {
32
	// _hostname = InetAddress.getLocalHost().getHostName();
33
	// _servers.put(_hostname, createNode(InetAddress.getLocalHost()));
34
	// }
35
	// catch(UnknownHostException e) {
36
	// /* We ignore this here and throw the error
37
	// when getLocalHost is called later.
38
	// */
39
	// }
40
	// }
41
42
	/**
43
	 * Create a Node for the suplied hostname. Nodes are are intended to be singletons in this application so if the Node exists it will be returned.
44
	 */
45
	public static Node createNode(String hostname) throws UnknownHostException {
46
		try {
47
			return createNode(hostname, null);
48
		} catch (DuplicateUserException e) {
49
			return containsNode(hostname, null);
50
		}
51
52
	}
53
54
	public static Node createNode(String hostname, Principal principal) throws UnknownHostException, DuplicateUserException {
55
		Node result = containsNode(hostname, principal);
56
		if (result == null) {
57
			InetAddress addr = InetAddress.getByName(hostname);
58
			return addNode(hostname, addr, principal);
59
		}
60
		throw new DuplicateUserException();
61
	}
62
63
	/**
64
	 * Create a Node for the suplied InetAddress. Nodes are are intended to be singletons in this application so if the Node exists it will be returned.
65
	 */
66
	public static Node createNode(InetAddress address) throws UnknownHostException {
67
		return createNode(address, null);
68
	}
69
70
	public static Node createNode(InetAddress address, Principal principal) throws UnknownHostException {
71
		String hostname = address.getHostName();
72
		Node result = containsNode(hostname, principal);
73
		if (result == null) {
74
			result = addNode(hostname, address, principal);
75
		}
76
		return result;
77
	}
78
79
	/**
80
	 * Returns the node that represents the local host.
81
	 * 
82
	 * @deprecated - use getLocalHost(User user)
83
	 */
84
	public static Node getLocalHost() throws UnknownHostException {
85
		return getLocalHost(null);
86
	}
87
88
	public static Node getLocalHost(Principal principal) throws UnknownHostException {
89
		/* The localhost is always in the first slot of the servers table */
90
		Node localNode = null;
91
		synchronized (_servers) {
92
			localNode = (Node) _servers.get(_hostname);
93
			if (localNode == null) {
94
				throw new UnknownHostException();
95
			}
96
		}
97
		return localNode;
98
	}
99
100
	public static void addNode(Node node) {
101
		String nodeName = node.getName();
102
		synchronized (_servers) {
103
			if (!_servers.containsKey(nodeName)) {
104
				_servers.put(nodeName, node);
105
			}
106
		}
107
	}
108
109
	private static Node addNode(String name, InetAddress addr, Principal principal) {
110
		if (name == null) {
111
			return null;
112
		}
113
114
		if (name.equals("localhost")) {
115
			try {
116
				name = InetAddress.getLocalHost().getHostName();
117
				InetAddress[] addrs = InetAddress.getAllByName(name);
118
				addr = addrs[0];
119
			} catch (UnknownHostException e) {
120
				/* We can ignore this */
121
			}
122
		}
123
124
		synchronized (_servers) {
125
			// Check if node already exist
126
			if (_servers.containsKey(name)) {
127
				Node existingNode = (Node) _servers.get(name);
128
				// Update the principal
129
				if (principal instanceof User) {
130
					existingNode.setUser((User) principal);
131
				} else if (principal instanceof Application) {
132
					existingNode.setApplication((Application) principal);
133
				}
134
				return existingNode;
135
			} else {
136
				Node newNode = new NodeImpl(name, addr);
137
				if (principal instanceof User) {
138
					newNode.setUser((User) principal);
139
				} else if (principal instanceof Application) {
140
					newNode.setApplication((Application) principal);
141
				}
142
				addNode(newNode);
143
				return newNode;
144
			}
145
		}
146
	}
147
148
	/**
149
	 * Searches the Node list based upon the hostname.
150
	 * 
151
	 * @return the Node if it exists, null otherwise.
152
	 */
153
	private static Node containsNode(String name, Principal principal) {
154
		Node node = null;
155
156
		if (name == null) {
157
			return null;
158
		}
159
160
		synchronized (_servers) {
161
			/* If this is "localhost" try and resolve its real name first */
162
			if (name.equals("localhost")) {
163
				try {
164
					name = InetAddress.getLocalHost().getHostName();
165
				} catch (UnknownHostException e) {
166
					/* We can ignore this */
167
				}
168
			}
169
170
			if (_servers.containsKey(name)) {
171
				node = (Node) _servers.get(name);
172
				if (principal == null) {
173
					// Node is the right one since no principal is supplied
174
				} else if ((principal instanceof User) && (node.getUser() != null)) {
175
					if (principal.getName().equals(node.getUser().getName())) {
176
						// Node is the right one since no principal is supplied
177
					} else {
178
						node = null;
179
					}
180
				} else if ((principal instanceof Application) && (node.getApplication() != null)) {
181
					if (principal.getName().equals(node.getApplication().getName())) {
182
						// Node is the right one since no principal is supplied
183
					} else {
184
						node = null;
185
					}
186
				}
187
			}
188
		}
189
190
		return node;
191
	}
192
193
	/**
194
	 * Searches the Node list based upon the InetAddress.
195
	 * 
196
	 * @return the Node if it exists, null otherwise.
197
	 */
198
	public static Node getNode(InetAddress addr) {
199
		return getNode(addr, null);
200
	}
201
202
	public static Node getNode(InetAddress addr, Principal principal) {
203
		/* Resolve the name and delegate */
204
		return containsNode(addr.getHostName(), principal);
205
	}
206
207
	public static Node getNode(String name, Principal principal) throws UnknownHostException {
208
		/* Resolve the name and delegate */
209
		return getNode(InetAddress.getByName(name), principal);
210
	}
211
212
}
(-)src-local-public/org/eclipse/hyades/execution/security/LoginFailedException.java (+30 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LoginFailedException.java,v 1.3 2005/05/01 16:59:32 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import org.eclipse.hyades.execution.local.control.AgentControllerUnavailableException;
16
17
public class LoginFailedException extends AgentControllerUnavailableException {
18
19
	private static final long serialVersionUID = 4048796749525233976L;
20
	private long _port;
21
22
	public LoginFailedException(long port) {
23
		_port = port;
24
	}
25
26
	public long getSecurePort() {
27
		return _port;
28
	}
29
30
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/DataProcessor.java (+18 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DataProcessor.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import org.eclipse.hyades.execution.core.IDataProcessor;
16
17
public interface DataProcessor extends IDataProcessor {
18
}
(-)src-local-public/org/eclipse/hyades/execution/security/AuthenticationListener.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AuthenticationListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import org.eclipse.hyades.execution.local.control.Connection;
16
17
public interface AuthenticationListener {
18
19
	void authenticationRequired(Connection connection);
20
21
	void authenticationSuccessful(Connection connection);
22
23
	void authenticationFailed(Connection connection);
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentRequestMonitorCommand.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentRequestMonitorCommand.java,v 1.1 2006/03/06 19:49:40 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class AgentRequestMonitorCommand extends MonitorPeerRequestCommand {
15
16
	public AgentRequestMonitorCommand() {
17
		super();
18
		_tag = RA_AGENT_REQUEST_MONITOR;
19
	}
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/RegisterAgentInterestCommand.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: RegisterAgentInterestCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class RegisterAgentInterestCommand extends SimpleAgentInfoCommand {
15
16
	/**
17
	 * 
18
	 */
19
	public RegisterAgentInterestCommand() {
20
		super();
21
		_tag = RA_REGISTER_AGENT_NOTIFICATION;
22
	}
23
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ProcessFactory.java (+56 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessFactory.java,v 1.3 2005/09/27 20:31:57 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class ProcessFactory {
16
17
	public static Process createProcess(Node node) {
18
		Process process = new ProcessImpl(node);
19
		if (node instanceof NodeImpl) {
20
			process.addProcessListener(((NodeImpl) node).getProcessListener());
21
		}
22
		return process;
23
	}
24
25
	public static Process createProcess(Node node, long pid) {
26
		Process process = new ProcessImpl(node, pid);
27
		if (node instanceof NodeImpl) {
28
			process.addProcessListener(((NodeImpl) node).getProcessListener());
29
		}
30
		return process;
31
	}
32
33
	public static Process createProcess(Node node, String executable) {
34
		Process process = new ProcessImpl(node, executable);
35
		if (node instanceof NodeImpl) {
36
			process.addProcessListener(((NodeImpl) node).getProcessListener());
37
		}
38
		return process;
39
	}
40
41
	public static Process createProcess(Node node, String executable, long pid) {
42
		Process process = new ProcessImpl(node, executable, pid);
43
		if (node instanceof NodeImpl) {
44
			process.addProcessListener(((NodeImpl) node).getProcessListener());
45
		}
46
		return process;
47
	}
48
49
	public static Process createProcess(Node node, String executable, String parameters) {
50
		Process process = new ProcessImpl(node, executable, parameters);
51
		if (node instanceof NodeImpl) {
52
			process.addProcessListener(((NodeImpl) node).getProcessListener());
53
		}
54
		return process;
55
	}
56
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/QueryAgentDetailsCommand.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: QueryAgentDetailsCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class QueryAgentDetailsCommand extends SimpleAgentInfoCommand implements Constants {
16
17
	public QueryAgentDetailsCommand() {
18
		super();
19
		_tag = RA_QUERY_AGENT_DETAILS;
20
	}
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ConsoleInfoCommand.java (+59 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ConsoleInfoCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.InputStream;
16
import java.io.OutputStream;
17
18
public class ConsoleInfoCommand extends SimpleProcessCommand {
19
	private InputStream _stdout;
20
	private InputStream _stderr;
21
	private OutputStream _stdin;
22
23
	public ConsoleInfoCommand(long pid, InputStream stdout, InputStream stderr, OutputStream stdin) {
24
		_tag = Constants.RA_CONSOLE_INFO;
25
		_stdout = stdout;
26
		_stderr = stderr;
27
		_stdin = stdin;
28
		super.setProcessId(pid);
29
	}
30
31
	public long getProcessId() {
32
		return super.getProcessId();
33
	}
34
35
	public InputStream getStdOut() {
36
		return _stdout;
37
	}
38
39
	public InputStream getStdErr() {
40
		return _stderr;
41
	}
42
43
	public OutputStream getStdIn() {
44
		return _stdin;
45
	}
46
47
	public int getSize() {
48
		return 0;
49
	}
50
51
	public int readFromBuffer(byte[] buffer, int offset) {
52
		return 0;
53
	}
54
55
	public int writeToBuffer(byte[] buffer, int offset) {
56
		return 0;
57
	}
58
59
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/MessageOverflowException.java (+38 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: MessageOverflowException.java,v 1.4 2005/10/08 14:28:53 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class MessageOverflowException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 1648853064662621578L;
21
22
	/**
23
	 * MessageOverflowException constructor comment.
24
	 */
25
	public MessageOverflowException() {
26
		super();
27
	}
28
29
	/**
30
	 * MessageOverflowException constructor comment.
31
	 * 
32
	 * @param s
33
	 *            java.lang.String
34
	 */
35
	public MessageOverflowException(String s) {
36
		super(s);
37
	}
38
}
(-)src-local-public/org/eclipse/hyades/execution/security/DuplicateUserException.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DuplicateUserException.java,v 1.3 2005/05/01 16:59:32 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import org.eclipse.hyades.execution.core.DaemonConnectException;
16
17
public class DuplicateUserException extends DaemonConnectException {
18
19
	private static final long serialVersionUID = 3979264742185579057L;
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/MonitorPeerRequestPortCommand.java (+53 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: MonitorPeerRequestPortCommand.java,v 1.3 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class MonitorPeerRequestPortCommand extends MonitorPeerRequestCommand {
15
	private long _peerPort = 10002;
16
	private long _targetPort = 10002;
17
18
	public MonitorPeerRequestPortCommand() {
19
		super();
20
		_tag = RA_CONTROLLER_REQUEST_MONITOR_PORT;
21
	}
22
23
	public int getSize() {
24
		return super.getSize() + (2 * sizeofLong);
25
	}
26
27
	public long getPeerPort() {
28
		return _peerPort;
29
	}
30
31
	public long getTargetPort() {
32
		return _targetPort;
33
	}
34
35
	public int readFromBuffer(byte[] buffer, int offset) {
36
		int current = super.readFromBuffer(buffer, offset);
37
38
		_targetPort = Message.readRALongFromBuffer(buffer, current);
39
		current += sizeofLong;
40
		_peerPort = Message.readRALongFromBuffer(buffer, current);
41
		current += sizeofLong;
42
43
		return current;
44
	}
45
46
	public int writeToBuffer(byte[] buffer, int offset) {
47
		int current = super.writeToBuffer(buffer, offset);
48
		current = Message.writeRALongToBuffer(buffer, current, _targetPort);
49
		current = Message.writeRALongToBuffer(buffer, current, _peerPort);
50
51
		return current;
52
	}
53
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ControlMessage.java (+391 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ControlMessage.java,v 1.8 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class ControlMessage extends Message {
16
17
	CommandElement[] _entries = null;
18
19
	/* The length field */
20
	long _length;
21
22
	/* The authentication key */
23
	protected RAString _key = new RAString("");
24
25
	/**
26
	 * ControlMessage constructor comment.
27
	 */
28
	public ControlMessage() {
29
		super();
30
		_type = RA_CONTROL_MESSAGE;
31
	}
32
33
	/**
34
	 * Insert the method's description here. Creation date: (6/2/00 4:35:08 PM)
35
	 * 
36
	 * @param command
37
	 *            com.ibm.jvmpi.common.CommandEntryElement
38
	 */
39
	public void appendCommand(CommandElement command) {
40
		if (_entries == null) {
41
			_entries = new CommandElement[1];
42
			_entries[0] = command;
43
			return;
44
		}
45
		synchronized (_entries) {
46
			// if(this.getSize()+command.getSize() >= MAX_MESSAGE_LENGTH)
47
			// throw new MessageOverflowException();
48
49
			CommandElement[] _oldElements = _entries;
50
			_entries = new CommandElement[_oldElements.length + 1];
51
			for (int i = 0; i < _oldElements.length; i++) {
52
				_entries[i] = _oldElements[i];
53
			}
54
			_entries[_oldElements.length] = command;
55
		}
56
	}
57
58
	/**
59
	 * Insert the method's description here. Creation date: (6/8/00 2:35:25 PM)
60
	 * 
61
	 * @return com.ibm.jvmpi.common.CommandEntryElement
62
	 * @param offset
63
	 *            int
64
	 */
65
	public CommandElement getCommand(int offset) {
66
		return _entries[offset];
67
	}
68
69
	/**
70
	 * Insert the method's description here. Creation date: (6/8/00 6:40:36 PM)
71
	 * 
72
	 * @return int
73
	 */
74
	public int getCommandCount() {
75
		return _entries.length;
76
	}
77
78
	/**
79
	 * Insert the method's description here. Creation date: (10/31/00 5:57:46
80
	 * PM)
81
	 */
82
	public RAString getKey() {
83
		return _key;
84
	}
85
86
	/* 185463 begin */
87
	/**
88
	 * Returns length of message read from message itself. Creation date:
89
	 * (09/27/00 5:57:46 PM)
90
	 */
91
	public long getLength() {
92
		return _length;
93
	}
94
95
	/* 185463 end */
96
97
	/**
98
	 * Insert the method's description here. Creation date: (6/8/00 10:21:47 AM)
99
	 * 
100
	 * @return short
101
	 */
102
	public int getSize() {
103
		int size = super.getSize();
104
105
		/* The length field */
106
		size += sizeofLong;
107
		/* Key size */
108
		size += (int) _key.getSize();
109
110
		/* Area for the count */
111
		size += sizeofLong;
112
113
		/* The commands */
114
115
		/* synchronized(_entries) { */
116
		for (int i = 0; i < _entries.length; i++)
117
			size += _entries[i].getSize();
118
		/* } */
119
		return size;
120
	}
121
122
	/**
123
	 * readFromBuffer - checks if the full message is contained in the buffer
124
	 * 
125
	 * @param buffer
126
	 *            data buffer to read from
127
	 * @param offset
128
	 *            offset with the data buffer to start reading from
129
	 * @param length
130
	 *            length of the data in the buffer
131
	 */
132
	public int readFromBuffer(byte[] buffer, int offset, int length) {
133
		int current = super.readFromBuffer(buffer, offset);
134
135
		long msgLength = Message.readRALongFromBuffer(buffer, current);
136
137
		/*
138
		 * First check if the message length field is contained in the data
139
		 * buffer so it is assured to be a valid length value and then check if
140
		 * the full message is contained in the data remaining in the buffer
141
		 */
142
		if (current + sizeofLong > offset + length || msgLength > length) {
143
			throw new ArrayIndexOutOfBoundsException("Not enough bytes in the buffer array");
144
		}
145
146
		return readFromBuffer(buffer, offset);
147
	}
148
149
	/**
150
	 * readFromBuffer method comment.
151
	 */
152
	public int readFromBuffer(byte[] buffer, int offset) {
153
		int current = super.readFromBuffer(buffer, offset);
154
155
		_length = Message.readRALongFromBuffer(buffer, current);
156
		if (_length > buffer.length) {
157
			throw new ArrayIndexOutOfBoundsException("Not enough bytes in the buffer array");
158
		}
159
160
		current += sizeofLong;
161
		/* authentication key */
162
		current = readRAStringFromBuffer(buffer, current, _key);
163
164
		/* How many commands are in this message */
165
		long count = Message.readRALongFromBuffer(buffer, current);
166
		current += sizeofLong;
167
168
		_entries = new CommandElement[(int) count];
169
170
		/* Read in each command */
171
		for (int i = 0; i < count; i++) {
172
			long tag = Message.readRALongFromBuffer(buffer, current);
173
174
			current += sizeofLong;
175
			CommandElement command = null;
176
			switch ((int) tag) {
177
			case (int) RA_AUTHENTICATE: // 0x01
178
				command = new AuthenticateCommand();
179
				current = ((AuthenticateCommand) command).readFromBuffer(buffer, current);
180
				break;
181
			case (int) RA_AUTHENTICATION_FAILED: // 0x02
182
				command = new AuthenticationFailedCommand();
183
				current = ((AuthenticationFailedCommand) command).readFromBuffer(buffer, current);
184
				break;
185
			case (int) RA_AUTHENTICATION_SUCCESSFUL: // 0x03
186
				command = new AuthenticationSuccessfulCommand();
187
				current = ((AuthenticationSuccessfulCommand) command).readFromBuffer(buffer, current);
188
				break;
189
			case (int) RA_SERVER_SECURITY_REQUIREMENTS: // 0x04
190
				command = new ServerSecurityInfoCommand();
191
				current = ((ServerSecurityInfoCommand) command).readFromBuffer(buffer, current);
192
				break;
193
			case (int) RA_LAUNCH_PROCESS: // 0x10
194
				command = new LaunchProcessCommand();
195
				current = ((LaunchProcessCommand) command).readFromBuffer(buffer, current);
196
				break;
197
			case (int) RA_QUERY_PROCESS_LIST: // 0x11
198
				command = new QueryProcessListCommand();
199
				current = ((QueryProcessListCommand) command).readFromBuffer(buffer, current);
200
				break;
201
			case (int) RA_QUERY_AGENT_LIST: // 0x12
202
				command = new QueryAgentListCommand();
203
				current = ((QueryAgentListCommand) command).readFromBuffer(buffer, current);
204
				break;
205
			case (int) RA_REGISTER_AGENT_NOTIFICATION: // 0x13
206
				command = new RegisterAgentInterestCommand();
207
				current = ((RegisterAgentInterestCommand) command).readFromBuffer(buffer, current);
208
				break;
209
			case (int) RA_ATTACH_TO_AGENT: // 0x14
210
				command = new AttachToAgentCommand();
211
				current = ((AttachToAgentCommand) command).readFromBuffer(buffer, current);
212
				break;
213
			case (int) RA_DETACH_FROM_AGENT: // 0x15
214
				command = new DetachFromAgentCommand();
215
				current = ((DetachFromAgentCommand) command).readFromBuffer(buffer, current);
216
				break;
217
			case (int) RA_START_MONITORING_AGENT_REMOTE: // 0x16
218
				command = new StartMonitoringRemoteAgentCommand();
219
				current = ((StartMonitoringRemoteAgentCommand) command).readFromBuffer(buffer, current);
220
				break;
221
			case (int) RA_START_MONITORING_AGENT_LOCAL: // 0x17
222
				command = new StartMonitoringLocalAgentCommand();
223
				current = ((StartMonitoringLocalAgentCommand) command).readFromBuffer(buffer, current);
224
				break;
225
			case (int) RA_STOP_MONITORING_AGENT: // 0x18
226
				command = new StopMonitorCommand();
227
				current = ((StopMonitorCommand) command).readFromBuffer(buffer, current);
228
				break;
229
			case (int) RA_SET_NAME_VALUE_PAIR: // 0x19
230
				command = new SetNVPairCommand();
231
				current = ((SetNVPairCommand) command).readFromBuffer(buffer, current);
232
				break;
233
			case (int) RA_CUSTOM_COMMAND: // 0x1A
234
				command = new CustomCommand();
235
				current = ((CustomCommand) command).readFromBuffer(buffer, current);
236
				break;
237
			case (int) RA_KILL_PROCESS: // 0x1B
238
				command = new KillProcessCommand();
239
				current = ((KillProcessCommand) command).readFromBuffer(buffer, current);
240
				break;
241
			case (int) RA_QUERY_AGENT_DETAILS: // 0x1C
242
				command = new QueryAgentDetailsCommand();
243
				current = ((QueryAgentDetailsCommand) command).readFromBuffer(buffer, current);
244
				break;
245
			case (int) RA_BINARY_CUSTOM_COMMAND: // 0x1D
246
				command = new BinaryCustomCommand();
247
				current = ((BinaryCustomCommand) command).readFromBuffer(buffer, current);
248
				break;
249
			case (int) RA_GET_PROPERTY_LIST: // 0x1E
250
				command = new GetPropertyListCommand();
251
				current = ((GetPropertyListCommand) command).readFromBuffer(buffer, current);
252
				break;
253
			case (int) RA_MANAGE_FILE: // 0x1F
254
				command = new ManageFileCommand();
255
				current = ((ManageFileCommand) command).readFromBuffer(buffer, current);
256
				break;
257
			case (int) RA_PROCESS_LAUNCHED: // 0x20
258
				command = new ProcessLaunchedCommand();
259
				current = ((ProcessLaunchedCommand) command).readFromBuffer(buffer, current);
260
				break;
261
			case (int) RA_PROCESS_LIST: // 0x21
262
				command = new RegisteredProcessListCommand();
263
				current = ((RegisteredProcessListCommand) command).readFromBuffer(buffer, current);
264
				break;
265
			case (int) RA_AGENT_LIST: // 0x22
266
				command = new ActiveAgentListCommand();
267
				current = ((ActiveAgentListCommand) command).readFromBuffer(buffer, current);
268
				break;
269
			case (int) RA_AGENT_ACTIVE: // 0x23
270
				command = new AgentActiveCommand();
271
				current = ((AgentActiveCommand) command).readFromBuffer(buffer, current);
272
				break;
273
			case (int) RA_AGENT_INACTIVE: // 0x24
274
				command = new AgentInactiveCommand();
275
				current = ((AgentInactiveCommand) command).readFromBuffer(buffer, current);
276
				break;
277
			case (int) RA_ERROR_STRING: // 0x25
278
				command = new ErrorCommand();
279
				current = ((ErrorCommand) command).readFromBuffer(buffer, current);
280
				break;
281
			case (int) RA_ATTACH_SUCCESSFUL: // 0x26
282
				break; // Not used
283
			case (int) RA_ATTACH_FAILED: // 0x27
284
				break; // Not used
285
			case (int) RA_AGENT_DETAILS: // 0x28
286
				command = new AgentDetailsCommand();
287
				current = ((AgentDetailsCommand) command).readFromBuffer(buffer, current);
288
				break;
289
			case (int) RA_PROCESS_EXITED: // 0x29
290
				command = new ProcessExitedCommand();
291
				current = ((ProcessExitedCommand) command).readFromBuffer(buffer, current);
292
				break;
293
			case (int) RA_PROPERTY_LIST: // 0x2A
294
				command = new PropertyListCommand();
295
				current = ((PropertyListCommand) command).readFromBuffer(buffer, current);
296
				break;
297
			case (int) RA_AGENT_QUERY_STATE: // 0x2B
298
				command = new AgentQueryStateCommand();
299
				current = ((AgentQueryStateCommand) command).readFromBuffer(buffer, current);
300
				break;
301
			case (int) RA_AGENT_ATTACHED: // 0x2C
302
				command = new AgentAttachedCommand();
303
				current = ((AgentAttachedCommand) command).readFromBuffer(buffer, current);
304
				break;
305
			case (int) RA_AGENT_DETACHED: // 0x2D
306
				command = new AgentDetachedCommand();
307
				current = ((AgentDetachedCommand) command).readFromBuffer(buffer, current);
308
				break;
309
			case (int) RA_LOCAL_AGENT_ACTIVE: // 0x30
310
				break; // Not used
311
			case (int) RA_AGENT_SCOPING_INFORMATION: // 0x31
312
				command = new AgentScopingInformationCommand();
313
				current = ((AgentScopingInformationCommand) command).readFromBuffer(buffer, current);
314
				break;
315
			case (int) RA_AGENT_CONFIGURATION: // 0x32
316
				command = new AgentConfigurationCommand();
317
				current = ((AgentConfigurationCommand) command).readFromBuffer(buffer, current);
318
				break;
319
			case (int) RA_AGENT_CONTROLLER_AVAILABLE: // 0x50
320
				break; // Not used
321
			case (int) RA_AGENT_CONTROLLER_UNAVAILABLE: // 0x51
322
				break; // Not used
323
			case (int) RA_AGENT_REQUEST_MONITOR: // 0x61
324
				command = new AgentRequestMonitorCommand();
325
				current = ((AgentRequestMonitorCommand) command).readFromBuffer(buffer, current);
326
				break;
327
			case (int) RA_CONTROLLER_REQUEST_MONITOR: // 0x62
328
				command = new MonitorPeerRequestCommand();
329
				current = ((MonitorPeerRequestCommand) command).readFromBuffer(buffer, current);
330
				break;
331
			case (int) RA_PEER_UNREACHABLE: // 0x63
332
				command = new PeerUnreachableCommand();
333
				current = ((PeerUnreachableCommand) command).readFromBuffer(buffer, current);
334
				break;
335
			case (int) RA_CONTROLLER_MONITOR_PEER: // 0x64
336
				break; // Not used
337
			case (int) RA_AGENT_REQUEST_MONITOR_PORT: // 0x65
338
				command = new AgentRequestMonitorPortCommand();
339
				current = ((AgentRequestMonitorPortCommand) command).readFromBuffer(buffer, current);
340
				break;
341
			case (int) RA_CONTROLLER_REQUEST_MONITOR_PORT: // 0x66
342
				command = new MonitorPeerRequestPortCommand();
343
				current = ((MonitorPeerRequestPortCommand) command).readFromBuffer(buffer, current);
344
				break;
345
			case (int) RA_RESOURCE_LOCATION: // 0x70
346
				command = new ResourceLocation();
347
				current = ((ResourceLocation) command).readFromBuffer(buffer, current);
348
				break;
349
			case (int) RA_CONSOLE_INFO: // 0x80
350
				break; // Not serializable
351
			}
352
			/* Store the command in the array */
353
			_entries[i] = command;
354
355
		}
356
		return current;
357
	}
358
359
	/**
360
	 * Insert the method's description here. Creation date: (10/31/00 5:59:07
361
	 * PM)
362
	 * 
363
	 * @param key
364
	 *            java.lang.String
365
	 */
366
	public void setKey(RAString key) {
367
		_key = key;
368
	}
369
370
	/**
371
	 * writeToBuffer method comment.
372
	 */
373
	public int writeToBuffer(byte[] buffer, int offset) {
374
		int current = super.writeToBuffer(buffer, offset);
375
376
		/* Insert the length */
377
		_length = getSize();
378
		current = Message.writeRALongToBuffer(buffer, current, _length);
379
		/* Insert the authentication key */
380
		current = writeRAStringToBuffer(buffer, current, _key);
381
382
		/* place the command count in the buffer */
383
		current = Message.writeRALongToBuffer(buffer, current, _entries.length);
384
385
		for (int i = 0; i < _entries.length; i++) {
386
			current = _entries[i].writeToBuffer(buffer, current);
387
388
		}
389
		return current;
390
	}
391
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ProcessLaunchedCommand.java (+177 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessLaunchedCommand.java,v 1.5 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.util.Vector;
16
17
public class ProcessLaunchedCommand extends DetailedProcessCommand {
18
19
	RAString _exe = new RAString("");
20
	RAString _args = new RAString("");
21
	Vector _environment = new Vector();
22
23
	/**
24
	 * ProcessLaunchedCommand constructor comment.
25
	 */
26
	public ProcessLaunchedCommand() {
27
		super();
28
		_tag = RA_PROCESS_LAUNCHED;
29
	}
30
31
	/**
32
	 * Insert the method's description here. Creation date: (10/31/00 7:42:56 PM)
33
	 * 
34
	 * @param name
35
	 *            java.lang.String
36
	 * @param value
37
	 *            java.lang.String
38
	 */
39
	public void addEnvironmentVariable(String name, String value) {
40
		_environment.addElement(new RAString(name + "=" + value));
41
	}
42
43
	/**
44
	 * Insert the method's description here. Creation date: (6/2/00 12:59:18 PM)
45
	 * 
46
	 * @return java.lang.String
47
	 */
48
	public String getArgs() {
49
		if (_args != null)
50
			return _args.getData();
51
		return null;
52
	}
53
54
	/**
55
	 * Insert the method's description here. Creation date: (11/9/00 9:02:18 AM)
56
	 * 
57
	 * @return java.lang.String[]
58
	 */
59
	public String[] getEnvironment() {
60
		String[] result = new String[_environment.size()];
61
		for (int i = 0; i < _environment.size(); i++) {
62
			result[i] = ((RAString) (_environment.elementAt(i))).getData();
63
		}
64
65
		return result;
66
	}
67
68
	/**
69
	 * Insert the method's description here. Creation date: (9/11/00 8:58:33 PM)
70
	 * 
71
	 * @return java.lang.String
72
	 */
73
	public String getExe() {
74
		if (_exe != null)
75
			return _exe.getData();
76
77
		return null;
78
	}
79
80
	/**
81
	 * Insert the method's description here. Creation date: (6/8/00 1:00:36 PM)
82
	 * 
83
	 * @return int
84
	 */
85
	public int getSize() {
86
		int size = super.getSize();
87
		size += _exe.getSize();
88
		size += _args.getSize();
89
90
		size += sizeofLong;
91
92
		for (int i = 0; i < _environment.size(); i++) {
93
			size += ((RAString) _environment.elementAt(i)).getSize();
94
		}
95
96
		return size;
97
	}
98
99
	/**
100
	 * Insert the method's description here. Creation date: (9/11/00 10:20:50 PM)
101
	 * 
102
	 * @return int
103
	 * @param buffer
104
	 *            byte[]
105
	 * @param offset
106
	 *            int
107
	 */
108
	public int readFromBuffer(byte[] buffer, int offset) {
109
		int current = super.readFromBuffer(buffer, offset);
110
		current = Message.readRAStringFromBuffer(buffer, current, _exe);
111
		current = Message.readRAStringFromBuffer(buffer, current, _args);
112
113
		long listLength = Message.readRALongFromBuffer(buffer, current);
114
		current += sizeofLong;
115
		for (int i = 0; i < listLength; i++) {
116
			RAString envVar = new RAString("");
117
			current = Message.readRAStringFromBuffer(buffer, current, envVar);
118
			_environment.addElement(envVar);
119
		}
120
121
		return current;
122
123
	}
124
125
	/**
126
	 * Insert the method's description here. Creation date: (6/2/00 1:00:01 PM)
127
	 * 
128
	 * @param args
129
	 *            java.lang.String
130
	 */
131
	public void setArgs(String args) {
132
		_args = new RAString(args);
133
	}
134
135
	/**
136
	 * Insert the method's description here. Creation date: (9/11/00 8:58:07 PM)
137
	 * 
138
	 * @param exe
139
	 *            java.lang.String
140
	 */
141
	public void setExe(String exe) {
142
		_exe = new RAString(exe);
143
	}
144
145
	/**
146
	 * Insert the method's description here. Creation date: (7/21/00 2:36:20 PM)
147
	 * 
148
	 * @return int
149
	 * @param buffer
150
	 *            byte[]
151
	 * @param offset
152
	 *            int
153
	 */
154
155
	public void setEnvironment(String[] env) {
156
		if (env != null) {
157
			int count = env.length;
158
			for (int i = 0; i < count; i++) {
159
				RAString entry = new RAString(env[i]);
160
				_environment.add(entry);
161
			}
162
		}
163
	}
164
165
	public int writeToBuffer(byte[] buffer, int offset) {
166
		int current = super.writeToBuffer(buffer, offset);
167
		current = Message.writeRAStringToBuffer(buffer, current, _exe);
168
		current = Message.writeRAStringToBuffer(buffer, current, _args);
169
170
		current = Message.writeRALongToBuffer(buffer, current, _environment.size());
171
172
		for (int i = 0; i < _environment.size(); i++) {
173
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) _environment.elementAt(i)));
174
		}
175
		return current;
176
	}
177
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/LocalConsole.java (+287 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalConsole.java,v 1.8 2006/04/26 19:59:16 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.OutputStream;
18
import java.io.UnsupportedEncodingException;
19
import java.net.InetAddress;
20
import java.net.ServerSocket;
21
import java.net.UnknownHostException;
22
23
public class LocalConsole extends Console {
24
	private ConsoleOutReader _outReader = null;
25
	private ConsoleErrReader _errReader = null;
26
	private ConsoleWaitingThread _waitThread = null;
27
	private DataProcessor _processor = null;
28
	private boolean _done = false;
29
	private InputStream _stdout;
30
	private InputStream _stderr;
31
	private OutputStream _stdin;
32
33
	private int _bytesWritten = 0;
34
35
	/*
36
	 * Allows the console threads to wait until the streams are established
37
	 */
38
	private Object _processor_lock = new Object();
39
	private Object _stdin_lock = new Object();
40
	private Object _stdout_lock = new Object();
41
	private Object _stderr_lock = new Object();
42
43
	public LocalConsole() {
44
		this("Local Console");
45
	}
46
47
	public LocalConsole(String name) {
48
		super(name);
49
		this.setDaemon(true);
50
	}
51
52
	public LocalConsole(ThreadGroup group, String name) {
53
		super(group, name);
54
		this.setDaemon(true);
55
	}
56
57
	private synchronized int getConsoleBytesWritten() {
58
		return _bytesWritten;
59
	}
60
61
	public long getIP() {
62
		return 0;
63
	}
64
65
	public long getPort() {
66
		return 0;
67
	}
68
69
	public ServerSocket getServerSocket() {
70
		return null;
71
	}
72
73
	public void run() {
74
		_outReader = new ConsoleOutReader();
75
		_outReader.start();
76
		_errReader = new ConsoleErrReader();
77
		_errReader.start();
78
		_waitThread = new ConsoleWaitingThread();
79
		_waitThread.start();
80
	}
81
82
	public void start() {
83
		run();
84
	}
85
86
	private synchronized void setConsoleBytesWritten(int bytes) {
87
		_bytesWritten = bytes;
88
	}
89
90
	public void setDataProcessor(DataProcessor processor) {
91
		synchronized (_processor_lock) {
92
			_processor = processor;
93
			_processor_lock.notifyAll();
94
		}
95
	}
96
97
	public void setStdOut(InputStream stdout) {
98
		synchronized (_stdout_lock) {
99
			_stdout = stdout;
100
			_stdout_lock.notifyAll();
101
		}
102
	}
103
104
	public void setStdErr(InputStream stderr) {
105
		synchronized (_stderr_lock) {
106
			_stderr = stderr;
107
			_stderr_lock.notifyAll();
108
		}
109
	}
110
111
	public void setStdIn(OutputStream stdin) {
112
		synchronized (_stdin_lock) {
113
			_stdin = stdin;
114
			_stdin_lock.notifyAll();
115
		}
116
	}
117
118
	public DataProcessor getDataProcessor() {
119
		return _processor;
120
	}
121
122
	public void write(String data) {
123
		if (_stdin == null) {
124
			synchronized (_stdin_lock) {
125
				try {
126
					_stdin_lock.wait();
127
				} catch (InterruptedException e) {
128
					return;
129
				}
130
			}
131
		}
132
133
		byte b[];
134
		try {
135
			b = data.getBytes("UTF-8");
136
		} catch (UnsupportedEncodingException e) {
137
			b = data.getBytes();
138
		}
139
140
		try {
141
			_stdin.write(b);
142
			_stdin.flush();
143
		} catch (IOException e) {
144
			return;
145
		}
146
	}
147
148
	/* Closes this console */
149
	public void close() {
150
		_done = true;
151
		if (_outReader != null) {
152
			_outReader.interrupt();
153
		}
154
		if (_errReader != null) {
155
			_errReader.interrupt();
156
		}
157
		if (_waitThread != null) {
158
			_waitThread.interrupt();
159
		}
160
	}
161
162
	class ConsoleOutReader extends Thread {
163
		private byte[] buffer = new byte[1024];
164
165
		public ConsoleOutReader() {
166
			setName("Console Output Reader");
167
		}
168
169
		public void run() {
170
			synchronized (_stdout_lock) {
171
				if (_stdout == null) {
172
					try {
173
						_stdout_lock.wait();
174
					} catch (InterruptedException e) {
175
					}
176
				}
177
			}
178
179
			while (!_done) {
180
				int byteRead = -1;
181
				try {
182
					byteRead = _stdout.read(buffer);
183
				} catch (IOException e1) {
184
				}
185
186
				if (byteRead == -1) {
187
					_done = true;
188
				} else {
189
					try {
190
						synchronized (_processor_lock) {
191
							if (_processor == null) {
192
								try {
193
									_processor_lock.wait(30000);
194
								} catch (InterruptedException e) {
195
								} // 30 sec max?
196
							}
197
							if (_processor != null) {
198
								_processor.incommingData(buffer, byteRead, InetAddress.getLocalHost());
199
								setConsoleBytesWritten(byteRead);
200
							} else {
201
								System.out.print(new String(buffer, 0, byteRead));
202
							}
203
						}
204
					} catch (UnknownHostException e) {
205
						// Error handling console
206
					}
207
				}
208
			}
209
		}
210
	}
211
212
	class ConsoleErrReader extends Thread {
213
		private byte[] buffer = new byte[1024];
214
215
		public ConsoleErrReader() {
216
			setName("Console Error Reader");
217
		}
218
219
		public void run() {
220
			synchronized (_stderr_lock) {
221
				if (_stderr == null) {
222
					try {
223
						_stderr_lock.wait();
224
					} catch (InterruptedException e) {
225
					}
226
				}
227
			}
228
229
			while (!_done) {
230
				int byteRead = -1;
231
				try {
232
					byteRead = _stderr.read(buffer);
233
				} catch (IOException e1) {
234
				}
235
236
				if (byteRead == -1) {
237
					_done = true;
238
				} else {
239
					try {
240
						synchronized (_processor_lock) {
241
							if (_processor == null) {
242
								try {
243
									_processor_lock.wait(30000);
244
								} catch (InterruptedException e) {
245
								} // 30 sec max?
246
							}
247
							if (_processor != null) {
248
								_processor.incommingData(buffer, byteRead, InetAddress.getLocalHost());
249
								setConsoleBytesWritten(byteRead);
250
							} else {
251
								System.err.print(new String(buffer, 0, byteRead));
252
							}
253
						}
254
					} catch (UnknownHostException e) {
255
						// Error handling console
256
					}
257
				}
258
			}
259
		}
260
	}
261
262
	class ConsoleWaitingThread extends Thread {
263
		public ConsoleWaitingThread() {
264
			setName("Console Waiting Notification");
265
		}
266
267
		public void run() {
268
			while (!_done) {
269
				try {
270
					sleep(3000); // 3 sec console polling
271
				} catch (Exception e) {
272
				}
273
274
				if (getConsoleBytesWritten() == 0) {
275
					synchronized (_processor_lock) {
276
						if (_processor != null) {
277
							_processor.waitingForData();
278
						}
279
					}
280
				} else {
281
					setConsoleBytesWritten(0);
282
				}
283
			}
284
		}
285
	}
286
287
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/NoSuchApplicationException.java (+27 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: NoSuchApplicationException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
/**
16
 * @author rduggan
17
 * 
18
 * To change this generated comment edit the template variable "typecomment": Window>Preferences>Java>Templates. To enable and disable the creation of type comments go to Window>Preferences>Java>Code Generation.
19
 */
20
public class NoSuchApplicationException extends Exception {
21
22
	/**
23
	 * Stream-Unique IDentifier (SUID) of this class
24
	 */
25
	private static final long serialVersionUID = 3694219616735552248L;
26
27
}
(-)src-local-public/org/eclipse/hyades/execution/core/file/socket/SocketChannelFactory.java (+96 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SocketChannelFactory.java,v 1.5 2006/10/30 18:25:55 jptoomey Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.hyades.execution.core.file.socket;
14
15
import java.io.IOException;
16
import java.net.InetSocketAddress;
17
import java.net.Socket;
18
19
/**
20
 * Factory to create the local socket channel abstraction, this factory offers a default instance to use for normal unsecure socket establishment but other factories can be implemented that implement the socket channel factory interface and used where socket channel factories are applicable and required
21
 * 
22
 * @author Scott E. Schneider
23
 */
24
public class SocketChannelFactory implements ISocketChannelFactory {
25
26
	/**
27
	 * The default socket channel factory instance
28
	 */
29
	private static final ISocketChannelFactory factory;
30
31
	/**
32
	 * Create and store the singleton instance, not using on demand creation, always create on class load
33
	 */
34
	static {
35
		factory = new SocketChannelFactory();
36
	}
37
38
	/**
39
	 * Default instance accessor method
40
	 * 
41
	 * @return the default socket channel factory, another implementation is possible by implementing the socket channel factory interface
42
	 */
43
	public static ISocketChannelFactory getInstance() {
44
		return SocketChannelFactory.factory;
45
	}
46
47
	/**
48
	 * Limit instantiation to factory extenders
49
	 */
50
	protected SocketChannelFactory() {
51
	}
52
53
	/*
54
	 * (non-Javadoc)
55
	 * 
56
	 * @see org.eclipse.hyades.execution.core.file.socket.ISocketChannelFactory#create(java.net.InetSocketAddress)
57
	 */
58
	public ISocketChannel create(InetSocketAddress address) throws IOException {
59
		return this.create(address, 60000);
60
	}
61
62
	/*
63
	 * (non-Javadoc)
64
	 * 
65
	 * @see org.eclipse.hyades.execution.core.file.socket.ISocketChannelFactory#create(java.net.InetSocketAddress, int)
66
	 */
67
	public ISocketChannel create(InetSocketAddress address, int timeout) throws IOException {
68
		java.nio.channels.SocketChannel socketChannel = java.nio.channels.SocketChannel.open();
69
		socketChannel.configureBlocking(true);
70
		Socket socket = socketChannel.socket();
71
		socket.setSoTimeout(timeout);
72
		socket.setTcpNoDelay(true);
73
		socket.setReuseAddress(true);
74
		socketChannel.connect(address);
75
		return new SocketChannel(socketChannel);
76
	}
77
78
	/*
79
	 * (non-Javadoc)
80
	 * 
81
	 * @see org.eclipse.hyades.execution.core.file.ISocketChannelFactory#create(java.nio.channels.SocketChannel)
82
	 */
83
	public ISocketChannel create(java.nio.channels.SocketChannel realChannel) {
84
		return new SocketChannel(realChannel);
85
	}
86
87
	/*
88
	 * (non-Javadoc)
89
	 * 
90
	 * @see org.eclipse.hyades.execution.core.file.ISocketChannelFactory#create(java.net.Socket)
91
	 */
92
	public ISocketChannel create(Socket socket) throws IOException {
93
		return new SocketChannel(socket);
94
	}
95
96
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/LocalConnectionImpl.java (+204 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalConnectionImpl.java,v 1.9 2006/04/06 15:28:01 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.util.Enumeration;
17
import java.util.Vector;
18
19
import org.eclipse.hyades.execution.local.common.CommandElement;
20
import org.eclipse.hyades.execution.local.common.Constants;
21
import org.eclipse.hyades.execution.local.common.ControlMessage;
22
import org.eclipse.hyades.execution.security.AuthenticationListener;
23
import org.eclipse.hyades.execution.security.LoginFailedException;
24
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
25
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
26
import org.eclipse.tptp.platform.agentcontroller.internal.DirectConnectionListener;
27
import org.eclipse.tptp.platform.agentcontroller.internal.impl.ConnectionFactoryImpl;
28
import org.eclipse.tptp.platform.agentcontroller.internal.impl.DirectControlConnectionImpl;
29
30
public class LocalConnectionImpl implements Connection, DirectConnectionListener {
31
	private Node _node = null;
32
	private ContextMapper _contextMapper;
33
	private long _context = 0;
34
	private Object _contextLock;
35
	private Vector _authenticationlisteners;
36
	private Vector _connectionListeners;
37
	private DirectControlConnectionImpl _control;
38
	private boolean _isActive = false;
39
40
	/**
41
	 * Please instantiate this through the factory method
42
	 *
43
	 */
44
	public LocalConnectionImpl() {
45
		_contextMapper = new ContextMapper();
46
		_contextLock = new Object();
47
		_authenticationlisteners = new Vector();
48
		_connectionListeners = new Vector();
49
	}
50
51
	public void addAuthenticationListener(AuthenticationListener listener) {
52
		synchronized(_authenticationlisteners) {
53
			if(!_authenticationlisteners.contains(listener)) {
54
				_authenticationlisteners.add(listener);
55
			}	
56
		}
57
	}
58
59
	public void addConnectionListener(ConnectionListener listener) {
60
		synchronized(_connectionListeners) {
61
			if(!_connectionListeners.contains(listener)) {
62
				_connectionListeners.add(listener);
63
			}	
64
		}
65
	}
66
67
	public void connect(Node node, int port) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException {
68
		/*
69
		 * Destroy the direct connection
70
		 */
71
		_control = ConnectionFactoryImpl.createDirectControlConnection();
72
		_control.setDirectConnectionListener(this);
73
74
		/*
75
		 * Notify the listeners that the connection is successful
76
		 */
77
		Enumeration listeners = _authenticationlisteners.elements();
78
		while(listeners.hasMoreElements()) {
79
			((AuthenticationListener)listeners.nextElement()).authenticationSuccessful(this);
80
		}
81
82
		_isActive = true;
83
	}
84
85
	public void disconnect() {
86
		/*
87
		 * Destroy the direct connection
88
		 */
89
		_control.removeDirectConnectionListener();
90
		_control = null;
91
92
		/*
93
		 * Notify the listeners that the connection has been closed
94
		 */
95
		Enumeration listeners = _connectionListeners.elements();
96
		while(listeners.hasMoreElements()) {
97
			((ConnectionListener)listeners.nextElement()).connectionClosed(this);
98
		}
99
100
		_isActive = false;
101
	}
102
103
	public Node getNode() {
104
		return _node;
105
	}
106
107
	public int getPort() {
108
		return -1; // No port is being used for local AC
109
	}
110
111
	private void incommingCommand(Node node, CommandElement command) {
112
		long context = command.getContext();
113
		
114
		
115
		/* Intercept authentication requests */
116
		switch((int)command.getTag()) {
117
			case (int)Constants.RA_SERVER_SECURITY_REQUIREMENTS:
118
				break;
119
			case (int)Constants.RA_AUTHENTICATION_FAILED:
120
				break;
121
			case (int)Constants.RA_AUTHENTICATION_SUCCESSFUL:
122
				synchronized(_authenticationlisteners) {
123
					Enumeration listeners = _authenticationlisteners.elements();
124
					while(listeners.hasMoreElements()) {
125
						((AuthenticationListener)listeners.nextElement()).authenticationSuccessful(this);
126
					}
127
				}
128
				break;
129
			default:
130
				/* Find the command handler associated with this contextId and
131
				   forward the message appropriately.
132
				*/
133
				CommandHandler ch = _contextMapper.getHandler(context);
134
				if(ch != null) {
135
					ch.incommingCommand(node, command);
136
//					_contextMapper.removeContext(context); // Prevent memory leak?
137
				}	
138
				else {
139
					//TODO: Handle the case where command cannot be sent
140
				}
141
		}
142
	}
143
144
	public boolean isActive() {
145
		return _isActive;
146
	}
147
148
	public void objectReceived(Object obj) {
149
		if(obj instanceof ControlMessage) {
150
			ControlMessage cmsg = (ControlMessage)obj;
151
			int count = cmsg.getCommandCount();
152
			for(int i = 0; i < count; i++) {
153
				incommingCommand(_node, cmsg.getCommand(i));
154
			}
155
		}
156
	}
157
158
	public void peerClosed() {
159
		_isActive = false;
160
	}
161
162
	public void removeAuthenticationListener(AuthenticationListener listener) {
163
		synchronized(_authenticationlisteners) {
164
			if(_authenticationlisteners.contains(listener)) {
165
				_authenticationlisteners.remove(listener);
166
			}	
167
		}
168
	}
169
170
	public void removeConnectionListener(ConnectionListener listener) {
171
		synchronized(_connectionListeners) {
172
			if(_connectionListeners.contains(listener)) {
173
				_connectionListeners.remove(listener);
174
			}	
175
		}
176
	}
177
178
	/**
179
	 * Send the message to the Agent Controller, not agents
180
	 */
181
	public void sendMessage(ControlMessage msg, CommandHandler handler) throws IOException {
182
		if(handler != null) {
183
			synchronized(_contextLock) {
184
				int numCommands = msg.getCommandCount();
185
186
				for(int i = 0; i < numCommands; i++) {
187
					msg.getCommand(i).setContext(_context);
188
					_contextMapper.addContext(_context, handler);
189
					_context++;
190
				}
191
			}
192
		} else {
193
			//No need to register a callback context since null is passed to us
194
		}
195
		_control.sendToQueue(msg);
196
	}
197
198
	public void setNode(Node node) {
199
		_node = node;
200
		_contextMapper.addContext(0, _node);
201
		_context++;
202
	}
203
204
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ProcessImpl.java (+807 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessImpl.java,v 1.15 2006/12/14 23:11:18 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.util.Enumeration;
17
import java.util.Vector;
18
19
import org.eclipse.hyades.execution.local.common.CommandElement;
20
import org.eclipse.hyades.execution.local.common.Console;
21
import org.eclipse.hyades.execution.local.common.ConsoleInfoCommand;
22
import org.eclipse.hyades.execution.local.common.ConsoleNotStartedException;
23
import org.eclipse.hyades.execution.local.common.Constants;
24
import org.eclipse.hyades.execution.local.common.ControlMessage;
25
import org.eclipse.hyades.execution.local.common.DetailedAgentInfoCommand;
26
import org.eclipse.hyades.execution.local.common.ErrorCommand;
27
import org.eclipse.hyades.execution.local.common.LaunchProcessCommand;
28
import org.eclipse.hyades.execution.local.common.LocalConsole;
29
import org.eclipse.hyades.execution.local.common.MonitorPeerRequestCommand;
30
import org.eclipse.hyades.execution.local.common.MultiplexedDataServer;
31
import org.eclipse.hyades.execution.local.common.ProcessExitedCommand;
32
import org.eclipse.hyades.execution.local.common.ProcessLaunchedCommand;
33
import org.eclipse.hyades.execution.local.common.SimpleAgentInfoCommand;
34
35
public class ProcessImpl implements Process, AgentListener, ConnectionListener {
36
	protected String _name = null;
37
38
	protected String _exe = null;
39
40
	protected String _params = null;
41
42
	protected String _location = null;
43
44
	protected String _processId = null;
45
46
	protected String _UUID = null;
47
48
	protected Node _node = null;
49
50
	protected Console _console = null;
51
52
	protected boolean _isActive = false;
53
54
	protected boolean _isComplete = false;
55
56
	protected Vector _agents = new Vector(10);
57
58
	protected Vector _variables = new Vector(20);
59
60
	protected Vector _listeners = new Vector(10);
61
62
	/* This is a lock for launching the process as this is synchronous */
63
	private Object _launcherLock = new Object();
64
65
	/*
66
	 * In eclipse, the model changes need to be done on the UI thread, this requires a bit of additional locking that, by rights, shouldn't be required
67
	 */
68
	private static Object _eclipseLock = new Object();
69
70
	/*
71
	 * Lock used for waitForAgent(...) method and agentActive(...) method notification
72
	 */
73
	private Object _waitForAgentLock = new Object();
74
75
	private boolean _noSuchAliasExceptionThrown = false;
76
77
	public ProcessImpl(Node node) {
78
		this(node, 0);
79
	}
80
81
	public ProcessImpl(Node node, long pid) {
82
		this(node, null, pid);
83
	}
84
85
	public ProcessImpl(Node node, String executable) {
86
		this(node, executable, null);
87
	}
88
89
	public ProcessImpl(Node node, String executable, String parameters) {
90
		_node = node;
91
		_exe = executable;
92
		_params = parameters;
93
		_console = getConsole();
94
	}
95
96
	public ProcessImpl(Node node, String executable, long pid) {
97
		_node = node;
98
		_exe = executable;
99
		_processId = new Long(pid).toString();
100
	}
101
102
	/**
103
	 * @see Process#launch()
104
	 */
105
	public void launch() throws ProcessActiveException, NotConnectedException, NoSuchApplicationException {
106
		/*
107
		 * Bug 112677 Here we use a static object lock to make sure each ProcessImpl will not cross each other when launching a process. Even though the ProcessImpl objects are isolated from each other, they are sharing the same Connection object which is used to send messages to the Agent Controller
108
		 */
109
		synchronized (_eclipseLock) { // Bug 112677 Multiple launches in quick
110
			// succession hangs
111
112
			/* Determine if the process is already launched or if it has exited */
113
			if (isActive() || _isComplete) {
114
				throw new ProcessActiveException();
115
			}
116
117
			/* Launch the process */
118
			ControlMessage message = new ControlMessage();
119
			LaunchProcessCommand command = new LaunchProcessCommand();
120
			command.setExe(_exe);
121
			command.setArgs(_params);
122
			command.setLocation(_location);
123
124
			/* Setup the console */
125
			_console = getConsole();
126
			_console.start();
127
			try {
128
				command.setConsole(_console);
129
			} catch (ConsoleNotStartedException e) {
130
				/* We just started the console so this isn't going to happen */
131
			}
132
133
			Enumeration e1 = _variables.elements();
134
			while (e1.hasMoreElements()) {
135
				Variable var = (Variable) e1.nextElement();
136
				command.addEnvironmentVariable(var.getName(), var.getValue());
137
			}
138
139
			/*
140
			 * Enumerate all the agents and add the interest only if autoAttach is true
141
			 */
142
			Enumeration e2 = _agents.elements();
143
			while (e2.hasMoreElements()) {
144
				Agent agent = (Agent) e2.nextElement();
145
				command.addAgent(agent.getName());
146
			}
147
148
			message.appendCommand(command);
149
			Connection connection = _node.getConnection();
150
			try {
151
				/*
152
				 * We need to listen in case this connection gets dropped while waiting for the launch to happen
153
				 */
154
				connection.addConnectionListener(this);
155
				connection.sendMessage(message, new CommandHandler() {
156
					public void incommingCommand(Node node, CommandElement command) {
157
						handleCommand(command);
158
					}
159
				});
160
			} catch (IOException e) {
161
				throw new NotConnectedException();
162
			}
163
164
			synchronized (_launcherLock) {
165
				try {
166
					/*
167
					 * Never wait more than 10 seconds in case something goes wrong
168
					 */
169
					_launcherLock.wait(10000);
170
				} catch (InterruptedException e) {
171
					/* We may need to handle this exception */
172
				}
173
			}
174
175
			/* If we have a pending NoSuchApplication error we need to throw it. */
176
			if (_noSuchAliasExceptionThrown) {
177
				_noSuchAliasExceptionThrown = false;
178
				throw new NoSuchApplicationException();
179
			}
180
181
		} // _eclipseLock
182
	}
183
184
	/**
185
	 * @see Process#kill(long)
186
	 */
187
	public void kill(long delay) throws InactiveProcessException, NotConnectedException {
188
		if (_node == null) {
189
			throw new InactiveProcessException();
190
		}
191
		_node.killProcess(this);
192
	}
193
194
	/**
195
	 * @see Process#addAgent()
196
	 */
197
	public void addAgent(Agent agent) {
198
		if (!_agents.contains(agent)) {
199
			_agents.addElement(agent);
200
		}
201
202
	}
203
204
	public void removeAgent(Agent agent) {
205
		if (_agents.contains(agent)) {
206
			_agents.remove(agent);
207
		}
208
	}
209
210
	/**
211
	 * @see Process#listAgents()
212
	 */
213
	public Enumeration listAgents() {
214
		return ((Vector) _agents.clone()).elements();
215
	}
216
217
	/**
218
	 * Remove agents from the process if their name do not exist in the list provided
219
	 * 
220
	 * @param newList
221
	 *            List of agents that should not be removed
222
	 */
223
	// Bug 71586 begins
224
	public void removeInactiveAgents(String[] newList) {
225
		Enumeration agents = listAgents();
226
		while (agents.hasMoreElements()) {
227
			Agent a = (Agent) agents.nextElement();
228
229
			boolean active = false;
230
			// Check if the agent is still shown in the new list
231
			for (int i = 0; i < newList.length; i++) {
232
				if (a.getName().equals(newList[i])) { // Compare the agent's
233
					// name
234
					active = true;
235
				}
236
			}
237
238
			// If the agent name does not appear in the new list, remove it.
239
			if (!active) {
240
				_agents.remove(a);
241
			}
242
		}
243
	}
244
245
	// Bug 71586 ends
246
247
	/**
248
	 * @see Process#getAgentsByType()
249
	 */
250
	public Enumeration getAgentsByType(String type) {
251
		Vector results = new Vector();
252
		synchronized (_agents) {
253
			Enumeration agents = listAgents();
254
			while (agents.hasMoreElements()) {
255
				Agent agent = (Agent) agents.nextElement();
256
				String agentType = agent.getType();
257
				if (agentType != null && agentType.equals(type)) {
258
					results.addElement(agent);
259
				}
260
			}
261
		}
262
		return results.elements();
263
	}
264
265
	public Agent getAgent(String name) {
266
		synchronized (_agents) {
267
			Enumeration agents = listAgents();
268
			while (agents.hasMoreElements()) {
269
				Agent agent = (Agent) agents.nextElement();
270
				if (agent.getName().equals(name)) {
271
					return agent;
272
				}
273
			}
274
		}
275
		return null;
276
	}
277
278
	/**
279
	 * @see Process#getEnvironment()
280
	 */
281
	public Enumeration getEnvironment() {
282
		return _variables.elements();
283
	}
284
285
	/**
286
	 * @see Process#addProcessListener(ProcessListener)
287
	 */
288
	public void addProcessListener(ProcessListener listener) {
289
		synchronized (_listeners) {
290
			if (!_listeners.contains(listener)) {
291
				_listeners.add(listener);
292
			}
293
		}
294
	}
295
296
	/**
297
	 * @see Process#removeProcessListener(ProcessListener)
298
	 */
299
	public void removeProcessListener(ProcessListener listener) {
300
		synchronized (_listeners) {
301
			if (_listeners.contains(listener)) {
302
				_listeners.remove(listener);
303
			}
304
		}
305
	}
306
307
	/**
308
	 * @see Process#getNode()
309
	 */
310
	public Node getNode() {
311
		return _node;
312
	}
313
314
	/**
315
	 * @see Process#setName()
316
	 */
317
	public void setName(String name) {
318
		_name = name;
319
	}
320
321
	/**
322
	 * @see Process#getName()
323
	 */
324
	public String getName() {
325
		return _name;
326
	}
327
328
	/**
329
	 * @see Process#getUUID()
330
	 */
331
	public String getUUID() {
332
		// Bug 58583
333
		int retryCount = 30; // retry 30 times
334
		int delay = 1000; // 1 sec between retry, total 30 sec max
335
		int i = 0;
336
337
		while ((_UUID == null) && (i < retryCount)) {
338
			try {
339
				Thread.sleep(delay);
340
			} catch (InterruptedException e) {
341
			}
342
			i++;
343
		}
344
345
		return _UUID;
346
	}
347
348
	/**
349
	 * @see Process#isActive()
350
	 */
351
	public boolean isActive() {
352
		return _isActive;
353
	}
354
355
	public void setActive(boolean isActive) {
356
		_isActive = isActive;
357
	}
358
359
	/**
360
	 * @see Process#getConsole()
361
	 */
362
	public Console getConsole() {
363
364
		if (_console == null) {
365
366
			Connection conn = getNode().getConnection();
367
			if (conn instanceof LocalConnectionImpl) {
368
				_console = new LocalConsole();
369
			} else {
370
				this._console = new Console(this._node);
371
			}
372
		}
373
		return _console;
374
	}
375
376
	public Console getLocalConsole() {
377
		if (_console == null) {
378
			_console = new LocalConsole();
379
		}
380
		return _console;
381
	}
382
383
	/**
384
	 * @see Process#addEnvironmentVariable()
385
	 */
386
	public void addEnvironmentVariable(Variable variable) throws ProcessActiveException {
387
		if (_isActive) {
388
			throw new ProcessActiveException();
389
		}
390
		_variables.add(variable);
391
392
	}
393
394
	/**
395
	 * @see Process#getEnvironmentVariable
396
	 */
397
	public Variable getEnvironmentVariable(String name) {
398
		Enumeration e = getEnvironment();
399
		while (e.hasMoreElements()) {
400
			Variable var = (Variable) e.nextElement();
401
			if (var.getName().equals(name)) {
402
				return var;
403
			}
404
		}
405
		return null;
406
	}
407
408
	/**
409
	 * @see Process#removeEnvironmentVariable
410
	 */
411
	public void removeEnvironmentVariable(Variable variable) throws ProcessActiveException {
412
		if (_isActive) {
413
			throw new ProcessActiveException();
414
		}
415
		_variables.remove(variable);
416
417
	}
418
419
	/**
420
	 * @see Process#setExecutable()
421
	 */
422
	public void setExecutable(String exe) throws ProcessActiveException {
423
		if (_isActive) {
424
			throw new ProcessActiveException();
425
		}
426
		_exe = exe;
427
	}
428
429
	/**
430
	 * @see Process#getExecutable()
431
	 */
432
	public String getExecutable() {
433
		return _exe;
434
	}
435
436
	/**
437
	 * @see Process#setParameters()
438
	 */
439
	public void setParameters(String params) throws ProcessActiveException {
440
		if (_isActive) {
441
			throw new ProcessActiveException();
442
		}
443
		_params = params;
444
	}
445
446
	/**
447
	 * @see Process#getParameters()
448
	 */
449
	public String getParameters() {
450
		return _params;
451
	}
452
453
	/**
454
	 * @see Process#setLocation()
455
	 */
456
	public void setLocation(String location) throws ProcessActiveException {
457
		if (_isActive) {
458
			throw new ProcessActiveException();
459
		}
460
		_location = location;
461
	}
462
463
	/**
464
	 * @see Process#getProcessId()
465
	 */
466
	public String getProcessId() throws InactiveProcessException {
467
		// Bug 58583
468
		int retryCount = 30; // retry 30 times
469
		int delay = 1000; // 1 sec between retry, total 30 sec max
470
		int i = 0;
471
472
		while ((_processId == null) && (i < retryCount)) {
473
			try {
474
				Thread.sleep(delay);
475
			} catch (InterruptedException e) {
476
			}
477
			i++;
478
		}
479
480
		if (_processId == null) {
481
			throw new InactiveProcessException();
482
		}
483
		return _processId;
484
	}
485
486
	public void setProcessId(String pid) {
487
		_processId = pid;
488
	}
489
490
	/**
491
	 * @see AgentListener#agentActive
492
	 */
493
	public void agentActive(Agent agent) {
494
		if (!_agents.contains(agent)) {
495
			_agents.add(agent);
496
		}
497
		/*
498
		 * Notify any waiting thread in the waitForAgent(...) method to minimize time spent waiting for next poll point.
499
		 */
500
		synchronized (this._waitForAgentLock) {
501
			this._waitForAgentLock.notifyAll();
502
		}
503
	}
504
505
	/**
506
	 * @see AgentListener#agentInactive
507
	 */
508
	public void agentInactive(Agent agent) {
509
		/* Should we remove this from the agent list? */
510
		if (agent instanceof AgentImpl) {
511
			AgentImpl _agent = (AgentImpl) agent;
512
			if (_agent._listeners != null && _agent._listeners.size() > 0) {
513
				for (int i = 0; i < _agent._listeners.size(); i++) {
514
					Object listener = _agent._listeners.get(i);
515
					if (listener instanceof MultiplexedDataServer)
516
						return;
517
				}
518
			}
519
		}
520
521
		if (_agents.contains(agent)) {
522
			_agents.remove(agent);
523
		}
524
	}
525
526
	/**
527
	 * @see AgentListener#error
528
	 */
529
	public void error(Agent agent, String errorId, String errorMessage) {
530
		/* Ignore */
531
	}
532
533
	/**
534
	 * @see AgentListener#handleCommand
535
	 */
536
	public void handleCommand(Agent agent, CommandElement command) {
537
		/* Ignore */
538
	}
539
540
	/**
541
	 * @see ConnectionListener#connectionClosed
542
	 */
543
	public void connectionClosed(Connection connection) {
544
		/*
545
		 * If there is a pending launch lock we need to release it as our connection has been lost
546
		 */
547
		synchronized (_launcherLock) {
548
			_launcherLock.notify();
549
		}
550
	}
551
552
	public String getlocation() {
553
		return _location;
554
	}
555
556
	/**
557
	 * @see Process#getUUID()
558
	 */
559
	public void setUUID(String uuid) {
560
		_UUID = uuid;
561
	}
562
563
	protected void handleCommand(CommandElement command) {
564
		Enumeration agents = null;
565
566
		switch ((int) command.getTag()) {
567
		case (int) Constants.RA_PROCESS_LAUNCHED:
568
			/* Only process a ProcessLaunched command once */
569
			if (_isActive) {
570
				break;
571
			}
572
573
			/* Extract all the information for this process */
574
			ProcessLaunchedCommand plc = (ProcessLaunchedCommand) command;
575
			_processId = new Long(plc.getProcessId()).toString();
576
			_UUID = plc.getProcessUUID();
577
578
			/* Capture all the environment variables */
579
			_variables.removeAllElements();
580
			String[] vars = plc.getEnvironment();
581
			for (int i = 0; i < vars.length; i++) {
582
				int equalsOffset = vars[i].indexOf('=');
583
				if (equalsOffset > 0) {
584
					String name = vars[i].substring(0, equalsOffset);
585
					String value = vars[i].substring(equalsOffset + 1);
586
					_variables.addElement(new Variable(name, value));
587
				}
588
			}
589
590
			_isActive = true;
591
592
			try {
593
				/* Inform the listeners that the process is launched */
594
				synchronized (_listeners) {
595
					Enumeration e = _listeners.elements();
596
					while (e.hasMoreElements()) {
597
						((ProcessListener) e.nextElement()).processLaunched(this);
598
					}
599
				}
600
601
			} finally {
602
				/*
603
				 * Remove our connection listener and if the connection is hosed we need to throw a exception
604
				 */
605
				Connection connection = _node.getConnection();
606
				connection.removeConnectionListener(this);
607
				// if(!connection.isActive()) {
608
				// throw new NotConnectedException();
609
				// }
610
611
				/*
612
				 * If our process failed to launch properly then we need to stop the console thread
613
				 */
614
				if (!isActive() && _console != null) {
615
					_console.close();
616
				}
617
618
			}
619
620
			/* Notify that the process is launched so "launch()" can return */
621
			synchronized (_launcherLock) {
622
				_launcherLock.notify();
623
			}
624
			break;
625
		case (int) Constants.RA_AGENT_ACTIVE:
626
		case (int) Constants.RA_AGENT_INACTIVE:
627
			/*
628
			 * When an agent becomes active/inactive we need to ensure it is a member of the agent list for this process. We also need to inform all the listeners for this agent that it is active/inactive. This is accomplished by delegating to the handleCommand() of the AgentImpl
629
			 */
630
			DetailedAgentInfoCommand aac = (DetailedAgentInfoCommand) command;
631
			synchronized (_agents) {
632
				Agent agent = null;
633
				agents = _agents.elements();
634
				while (agents.hasMoreElements()) {
635
					Agent current = (Agent) agents.nextElement();
636
					if (current.getName().equals(aac.getAgentName())) {
637
						agent = current;
638
						break;
639
					}
640
				}
641
				if (agent == null) {
642
					agent = AgentFactory.createAgent(this, aac.getAgentName(), aac.getAgentType()); // TODO: Should we do this
643
					// for RA_AGENT_INACTIVE?
644
					((AgentImpl) agent).setUUID(aac.getAgentUUID());
645
				}
646
647
				/*
648
				 * Forward this command to the agent so it can handle the details
649
				 */
650
				try {
651
					AgentImpl agentImpl = (AgentImpl) agent;
652
					if (agent.getUUID() == null) {
653
						agentImpl.setUUID(aac.getAgentUUID());
654
					}
655
					agentImpl.handleCommand(command);
656
657
				} catch (ClassCastException exc) {
658
					/*
659
					 * This is not an instance of AgentImpl, do not attempt to notify it is active
660
					 */
661
				}
662
663
			}
664
			break;
665
		case (int) Constants.RA_ERROR_STRING:
666
			/* When we are launching a process there could be an error */
667
			ErrorCommand ec = (ErrorCommand) command;
668
			if (ec.getErrorId().equals("RAC002")) {
669
				_noSuchAliasExceptionThrown = true;
670
				synchronized (_launcherLock) {
671
					_launcherLock.notify();
672
				}
673
			}
674
675
			agents = _agents.elements();
676
			while (agents.hasMoreElements()) {
677
				Agent agent = (Agent) agents.nextElement();
678
				if (agent.getName().equals(ec.getAgentName())) {
679
					try {
680
						((AgentImpl) agent).handleCommand(command);
681
					} catch (ClassCastException exc) {
682
						// TODO: Error casting agent
683
					}
684
685
				}
686
			}
687
688
			break;
689
		case (int) Constants.RA_PROCESS_EXITED:
690
			ProcessExitedCommand peCmd = (ProcessExitedCommand) command;
691
			if (_console != null) {
692
				_console.close(); /* Close the console port when process exits */
693
			}
694
695
			if (!_isComplete) {
696
				_isComplete = true;
697
				synchronized (_listeners) {
698
					Enumeration e = _listeners.elements();
699
					while (e.hasMoreElements()) {
700
						((ProcessListener) e.nextElement()).processExited(this);
701
					}
702
				}
703
704
				// Clean up process members as the process exits (avoid memory
705
				// leaks)
706
				this._listeners.clear();
707
				this._variables.clear();
708
				this._agents.clear();
709
710
			}
711
712
			/* Notify the agents */
713
			agents = _agents.elements();
714
			while (agents.hasMoreElements()) {
715
				Agent agent = (Agent) agents.nextElement(); // Notify all agents
716
				try {
717
					((AgentImpl) agent).handleCommand(command);
718
				} catch (ClassCastException exc) {
719
					// TODO: Error casting agent
720
				}
721
			}
722
723
			((NodeImpl) _node).removeProcess(peCmd.getProcessId());
724
725
			break;
726
		case (int) Constants.RA_CONSOLE_INFO:
727
			ConsoleInfoCommand ciCmd = (ConsoleInfoCommand) command;
728
			if (_console instanceof LocalConsole) {
729
				((LocalConsole) _console).setStdOut(ciCmd.getStdOut());
730
				((LocalConsole) _console).setStdErr(ciCmd.getStdErr());
731
				((LocalConsole) _console).setStdIn(ciCmd.getStdIn());
732
			}
733
			break;
734
		case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR:
735
		case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR_PORT: {
736
			MonitorPeerRequestCommand cmd = (MonitorPeerRequestCommand) command;
737
			String agentName = cmd.getAgentName();
738
739
			agents = _agents.elements();
740
			while (agents.hasMoreElements()) {
741
				Agent agent = (Agent) agents.nextElement(); // Notify all agents
742
				if (agent.getName().equals(agentName)) {
743
					try {
744
						((AgentImpl) agent).handleCommand(command);
745
					} catch (ClassCastException exc) {
746
						// TODO: Error casting agent
747
					}
748
				}
749
			}
750
751
			break;
752
		}
753
		default:
754
			if (command instanceof SimpleAgentInfoCommand) {
755
				/*
756
				 * Custom commands can be generated by agents running on this process. Find the proper agent and forward the message on to it. This gets invoked only when a launch is done not attach, as these are routed directly to the agent.
757
				 */
758
				Agent agent = getAgent(((SimpleAgentInfoCommand) command).getAgentName());
759
				try {
760
					if (agent != null) {
761
						((AgentImpl) agent).handleCommand(command);
762
					}
763
				} catch (ClassCastException e) {
764
					/* This isn;t our impl so we can ignore the command */
765
				}
766
			}
767
		}
768
	}
769
770
	/*
771
	 * (non-Javadoc)
772
	 * 
773
	 * Waits for a particular agent to be present or the timeout value to be reached; after the agent list returns (the internal agent list in this process instance is updated) the agent is retrieved via the get agent method. The timeout value is approximate since there is some time needed to execute the various operations within the loop and each wait is done timeout divided by 2000 times. For example, a 60000 (60 second) timeout would cause the loop to execute 30 times and wait for 2 seconds at the end of each process list query.
774
	 */
775
	public Agent waitForAgent(String agentType, String agentName, int timeout) throws NotConnectedException, InactiveProcessException {
776
777
		synchronized (this._waitForAgentLock) {
778
779
			// Change this from a polling model into a notify model (this is
780
			// good enough for now)
781
			try {
782
				for (int i = 0, j = timeout / 2000; i < j; i++) {
783
					this.getNode().fastListProcesses(); // bugzilla_92619 (without
784
					// this, agents are never
785
					// refreshed)
786
					for (Enumeration agents = this.listAgents(); agents.hasMoreElements();) {
787
						Agent agent = (Agent) agents.nextElement();
788
						if (agent.getName().indexOf(agentName) != -1) { // checks
789
							// for
790
							// proper
791
							// substring
792
							return agent;
793
						}
794
					}
795
					this._waitForAgentLock.wait(2000);
796
				}
797
			} catch (InterruptedException e) {
798
				// Do not need to handle this
799
				e.printStackTrace();
800
			}
801
802
			return null; // no agent was found in the allowed time
803
		}
804
805
	}
806
807
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentConfiguration.java (+91 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentConfiguration.java,v 1.5 2006/04/06 15:28:01 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.util.Vector;
16
17
public class AgentConfiguration {
18
	protected String _agentName = null;
19
	protected Vector _entries = new Vector();
20
21
	/**
22
	 * AgentConfiguration constructor comment.
23
	 */
24
	public AgentConfiguration() {
25
		super();
26
	}
27
28
	/**
29
	 * Insert the method's description here. Creation date: (11/9/00 8:18:32 AM)
30
	 * 
31
	 * @param param
32
	 *            an agent configuration entry
33
	 */
34
	public void addEntry(AgentConfigurationEntry entry) {
35
		_entries.addElement(entry);
36
	}
37
38
	/**
39
	 * Insert the method's description here. Creation date: (10/15/2001 3:47:31 PM)
40
	 */
41
	public void clear() {
42
		_entries.clear();
43
	}
44
45
	/**
46
	 * Insert the method's description here. Creation date: (11/9/00 8:20:58 AM)
47
	 * 
48
	 * @return java.lang.String
49
	 */
50
	public String getAgentName() {
51
		return _agentName;
52
	}
53
54
	/**
55
	 * Insert the method's description here. Creation date: (11/9/00 12:32:57 PM)
56
	 * 
57
	 * @return the requested agent configuration entry
58
	 * @param offset
59
	 *            int
60
	 */
61
	public AgentConfigurationEntry getEntryAt(int offset) {
62
		return (AgentConfigurationEntry) _entries.elementAt(offset);
63
	}
64
65
	/**
66
	 * Insert the method's description here. Creation date: (11/9/00 8:20:29 AM)
67
	 * 
68
	 * @param name
69
	 *            java.lang.String
70
	 */
71
	public void setAgentName(String name) {
72
		_agentName = name;
73
	}
74
75
	/**
76
	 * Insert the method's description here. Creation date: (11/9/00 12:30:28 PM)
77
	 * 
78
	 * @return int
79
	 */
80
	public int size() {
81
		return _entries.size();
82
	}
83
84
	/**
85
	 * Removes an entry from this configuration.
86
	 */
87
	public boolean removeEntry(AgentConfigurationEntry entry) {
88
		return _entries.removeElement(entry);
89
	}
90
91
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ExtendedDataServerListener.java (+49 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ExtendedDataServerListener.java,v 1.2 2005/09/30 21:45:08 slavescu Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.InputStream;
16
17
public interface ExtendedDataServerListener extends DataServerListener {
18
	/**
19
	 * @param buffer
20
	 *            byte[]
21
	 * @param length
22
	 *            int
23
	 * @param peer
24
	 *            java.net.InetAddress
25
	 */
26
	void incommingData(byte[] buffer, int offset, int length, java.net.InetAddress peer);
27
28
	/**
29
	 * @param buffer
30
	 *            char[]
31
	 * @param length
32
	 *            int
33
	 * @param peer
34
	 *            java.net.InetAddress
35
	 */
36
	void incommingData(char[] buffer, int offset, int length, java.net.InetAddress peer);
37
38
	/**
39
	 * @param data
40
	 *            byte[]
41
	 * @param length
42
	 *            int
43
	 * @param peer
44
	 *            java.net.InetAddress
45
	 */
46
	void invalidDataType(byte[] data, int offset, int length, java.net.InetAddress peer);
47
48
	void incommingStream(InputStream inputStream, java.net.InetAddress peer);
49
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentQueryStateCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentQueryStateCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentQueryStateCommand extends SimpleAgentInfoCommand {
16
17
	/**
18
	 * Constructor
19
	 */
20
	public AgentQueryStateCommand() {
21
		super();
22
		_tag = RA_AGENT_QUERY_STATE;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/RegisteredProcessListCommand.java (+90 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: RegisteredProcessListCommand.java,v 1.5 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class RegisteredProcessListCommand extends CommandElement implements Constants {
16
	private int _processListLength = 0;
17
	private long _processList[];
18
19
	/**
20
	 * QueryServerCommand constructor comment.
21
	 */
22
	public RegisteredProcessListCommand() {
23
		super();
24
		_tag = RA_PROCESS_LIST;
25
	}
26
27
	public RegisteredProcessListCommand(long[] p) {
28
		super();
29
		_tag = RA_PROCESS_LIST;
30
		_processList = p;
31
		_processListLength = p.length;
32
	}
33
34
	/**
35
	 * Insert the method's description here. Creation date: (9/12/00 12:14:34 AM)
36
	 * 
37
	 * @return long[]
38
	 */
39
	public long[] getProcessList() {
40
		return _processList;
41
	}
42
43
	/**
44
	 * getSize method comment.
45
	 */
46
	public int getSize() {
47
		int size = super.getSize();
48
49
		size += sizeofLong; // length
50
		size += (sizeofLong * _processListLength);
51
52
		return size;
53
	}
54
55
	/**
56
	 * readFromBuffer method comment.
57
	 */
58
	public int readFromBuffer(byte[] buffer, int offset) {
59
		int current = offset;
60
61
		current = super.readFromBuffer(buffer, current);
62
63
		_processListLength = (int) Message.readRALongFromBuffer(buffer, current);
64
		current += sizeofLong;
65
66
		_processList = new long[_processListLength];
67
		for (int i = 0; i < _processListLength; i++) {
68
			_processList[i] = Message.readRALongFromBuffer(buffer, current);
69
			current += sizeofLong;
70
		}
71
		return current;
72
	}
73
74
	/**
75
	 * writeToBuffer method comment.
76
	 */
77
	public int writeToBuffer(byte[] buffer, int offset) {
78
		int current = offset;
79
80
		current = super.writeToBuffer(buffer, current);
81
82
		current = Message.writeRALongToBuffer(buffer, current, (long) _processListLength);
83
84
		for (int i = 0; i < _processListLength; i++) {
85
			current = Message.writeRALongToBuffer(buffer, current, _processList[i]);
86
		}
87
88
		return current;
89
	}
90
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentAttachedCommand.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentAttachedCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentAttachedCommand extends SimpleAgentInfoCommand { // Bug 54376
16
17
	/**
18
	 * Constructor
19
	 */
20
	public AgentAttachedCommand() {
21
		super();
22
		_tag = RA_AGENT_ATTACHED;
23
	}
24
}
(-)src-local-public/org/eclipse/hyades/execution/security/UserFactory.java (+89 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: UserFactory.java,v 1.3 2005/09/13 16:46:21 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import java.util.Enumeration;
16
import java.util.Hashtable;
17
import java.util.Vector;
18
19
import org.eclipse.hyades.execution.local.control.Application;
20
21
public class UserFactory {
22
23
	private static Hashtable _table = new Hashtable();
24
25
	/**
26
	 * Create a user for a specific application so that we can have multiple
27
	 * connections open to a Node.
28
	 */
29
	public static synchronized User createUser(Application app, String name, String password) throws DuplicateUserException {
30
		Vector userList = (Vector) _table.get(app.getName());
31
32
		if (userList == null) {
33
			userList = new Vector();
34
			_table.put(app.getName(), userList);
35
		} else {
36
			Enumeration e = userList.elements();
37
			while (e.hasMoreElements()) {
38
				User user = (User) e.nextElement();
39
				if (user.getName().equals(name)) {
40
					throw new DuplicateUserException();
41
				}
42
			}
43
44
		}
45
46
		User user = new User(app, name, password);
47
		userList.add(user);
48
49
		return user;
50
	}
51
52
	public static synchronized void removeAllUsers(Application app) {
53
		_table.remove(app.getName());
54
55
	}
56
57
	public static User removeUser(Application app, String name) {
58
		Vector userList = (Vector) _table.get(app.getName());
59
		if (userList != null) {
60
			Object[] users = userList.toArray();
61
			for (int i = 0; i < users.length; i++) {
62
				User currentUser = (User) users[i];
63
				if (currentUser.getName().equals(name)) {
64
					userList.remove(i);
65
					return currentUser;
66
				}
67
			}
68
		}
69
		return null;
70
	}
71
72
	/**
73
	 * Retrieve a user for a specific application.
74
	 */
75
	public static synchronized User getUser(Application app, String name) {
76
		User user = null;
77
		Vector userList = (Vector) _table.get(app.getName());
78
		if (userList != null) {
79
			Enumeration e = userList.elements();
80
			while (e.hasMoreElements()) {
81
				user = (User) e.nextElement();
82
				if (user.getName().equals(name)) {
83
					return user;
84
				}
85
			}
86
		}
87
		return null;
88
	}
89
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AuthenticationFailedCommand.java (+63 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AuthenticationFailedCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AuthenticationFailedCommand extends CommandElement implements Constants {
16
	private long _ticket;
17
18
	public AuthenticationFailedCommand() {
19
		super();
20
		_tag = RA_AUTHENTICATION_FAILED;
21
	}
22
23
	public int getSize() {
24
		int size = super.getSize();
25
26
		size += sizeofLong;
27
28
		return size;
29
	}
30
31
	public long getTicket() {
32
		return _ticket;
33
	}
34
35
	public int readFromBuffer(byte[] buffer, int offset) {
36
		int current = offset;
37
38
		/*
39
		 * Cannot call super.readFromBuffer() since this command does not have a
40
		 * context
41
		 */
42
		// current = super.readFromBuffer(buffer, current);
43
		_ticket = Message.readRALongFromBuffer(buffer, current);
44
		current += sizeofLong;
45
46
		return current;
47
	}
48
49
	public int writeToBuffer(byte[] buffer, int offset) {
50
		int current = offset;
51
52
		/*
53
		 * Cannot call super.writeToBuffer() since this command does not have a
54
		 * context
55
		 */
56
		// current = super.writeToBuffer(buffer, current);
57
		current = Message.writeRALongToBuffer(buffer, current, _tag);
58
		current = Message.writeRALongToBuffer(buffer, current, _ticket);
59
60
		return current;
61
	}
62
63
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AuthenticateCommand.java (+76 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AuthenticateCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AuthenticateCommand extends CommandElement implements Constants {
16
	private RAString _name = new RAString("");
17
	private RAString _password = new RAString("");;
18
19
	public AuthenticateCommand() {
20
		super();
21
		_tag = RA_AUTHENTICATE;
22
	}
23
24
	public AuthenticateCommand(String name, String password) {
25
		this();
26
		_name = new RAString(name);
27
		_password = new RAString(password);
28
	}
29
30
	public void setName(String name) {
31
		_name = new RAString(name);
32
	}
33
34
	public void setPassword(String password) {
35
		_password = new RAString(password);
36
	}
37
38
	public int getSize() {
39
		int size = super.getSize();
40
41
		size += _name.getSize();
42
		size += _password.getSize();
43
44
		return size;
45
	}
46
47
	public int readFromBuffer(byte[] buffer, int offset) {
48
		int current = offset;
49
50
		/*
51
		 * Cannot call super.readFromBuffer() since this command does not have a
52
		 * context
53
		 */
54
		// current = super.readFromBuffer(buffer, current);
55
		current = Message.readRAStringFromBuffer(buffer, current, _name);
56
		current = Message.readRAStringFromBuffer(buffer, current, _password);
57
58
		return current;
59
	}
60
61
	public int writeToBuffer(byte[] buffer, int offset) {
62
		int current = offset;
63
64
		/*
65
		 * Cannot call super.writeToBuffer() since this command does not have a
66
		 * context
67
		 */
68
		// current = super.writeToBuffer(buffer, current);
69
		current = Message.writeRALongToBuffer(buffer, current, _tag);
70
		current = Message.writeRAStringToBuffer(buffer, current, _name);
71
		current = Message.writeRAStringToBuffer(buffer, current, _password);
72
73
		return current;
74
	}
75
76
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/MonitorPeerRequestCommand.java (+133 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: MonitorPeerRequestCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
import java.net.UnknownHostException;
17
18
public class MonitorPeerRequestCommand extends SimpleAgentInfoCommand {
19
20
	protected RABinaryArray _peerNode = new RABinaryArray();
21
	protected RABinaryArray _targetNode = new RABinaryArray();
22
	protected RAString _peerName = new RAString("");
23
	protected long _peerProcessId;
24
25
	private InetAddress _peerAddress = null;
26
	private InetAddress _targetAddress = null;
27
28
	/**
29
	 * CustomCommand constructor comment.
30
	 */
31
	public MonitorPeerRequestCommand() {
32
		super();
33
		_tag = RA_CONTROLLER_REQUEST_MONITOR;
34
	}
35
36
	/**
37
	 * getSize method comment.
38
	 */
39
	public int getSize() {
40
		return super.getSize() + _peerNode.getSize() + sizeofLong + _peerName.getSize();
41
42
	}
43
44
	public InetAddress getPeerNode() throws UnknownHostException {
45
		/* Check our cache */
46
		if (_peerAddress != null) {
47
			return _targetAddress;
48
		}
49
		if (_peerNode.length() == 0) {
50
			return null;
51
		}
52
		byte[] data = _peerNode.getData();
53
54
		/* Build a string representing the IP address in decimal form */
55
		String addr = new String();
56
		addr += convertPointAddress(new Byte(data[0]).intValue());
57
58
		for (int i = 1; i < _peerNode.length(); i++) {
59
			addr = addr + "." + convertPointAddress(new Byte(data[i]).intValue());
60
		}
61
62
		/* Lookup the InetAddress objects for this address */
63
		return InetAddress.getByName(addr);
64
	}
65
66
	public InetAddress getTargetNode() throws UnknownHostException {
67
		/* Check our cache */
68
		if (_targetAddress != null) {
69
			return _targetAddress;
70
		}
71
		if (_targetNode.length() == 0) {
72
			return null;
73
		}
74
		byte[] data = _targetNode.getData();
75
76
		/* Build a string representing the IP address in decimal form */
77
		String addr = new String();
78
		addr += convertPointAddress(new Byte(data[0]).intValue());
79
		for (int i = 1; i < _targetNode.length(); i++) {
80
			addr = addr + "." + convertPointAddress(new Byte(data[i]).intValue());
81
		}
82
83
		/* Lookup the InetAddress objects for this address */
84
		return InetAddress.getByName(addr);
85
86
	}
87
88
	public String getPeerAgentName() {
89
		if (_peerName != null) {
90
			return _peerName.getData();
91
		}
92
		return null;
93
	}
94
95
	public long getPeerProcessId() {
96
		return _peerProcessId;
97
	}
98
99
	/**
100
	 * readFromBuffer method comment.
101
	 */
102
	public int readFromBuffer(byte[] buffer, int offset) {
103
		int current = super.readFromBuffer(buffer, offset);
104
		current = Message.readRABinaryArrayFromBuffer(buffer, current, _targetNode);
105
		_peerProcessId = Message.readRALongFromBuffer(buffer, current);
106
		current += sizeofLong;
107
		current = Message.readRAStringFromBuffer(buffer, current, _peerName);
108
		current = Message.readRABinaryArrayFromBuffer(buffer, current, _peerNode);
109
		return current;
110
	}
111
112
	/**
113
	 * writeToBuffer method comment.
114
	 */
115
	public int writeToBuffer(byte[] buffer, int offset) {
116
		int current = super.writeToBuffer(buffer, offset);
117
		current = Message.writeRABinaryArrayToBuffer(buffer, current, _targetNode);
118
		current = Message.writeRALongToBuffer(buffer, current, _peerProcessId);
119
		current = Message.writeRAStringToBuffer(buffer, current, _peerName);
120
		current = Message.writeRABinaryArrayToBuffer(buffer, current, _peerNode);
121
		return current;
122
	}
123
124
	private int convertPointAddress(int pointAddress) {
125
		if (pointAddress < 0) {
126
			pointAddress = 256 - Math.abs(pointAddress);
127
128
		}
129
		return pointAddress;
130
131
	}
132
133
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentConfigurationEntry.java (+111 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentConfigurationEntry.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class AgentConfigurationEntry {
16
	protected String _type = null;
17
	protected String _name = null;
18
	protected String _value = null;
19
	protected boolean _enabled = true;
20
21
	/**
22
	 * AgentConfigurationEntry constructor comment.
23
	 */
24
	public AgentConfigurationEntry() {
25
		super();
26
	}
27
28
	/**
29
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
30
	 * 
31
	 * @return java.lang.String
32
	 */
33
	public java.lang.String getName() {
34
		return _name;
35
	}
36
37
	/**
38
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
39
	 * 
40
	 * @return java.lang.String
41
	 */
42
	public java.lang.String getType() {
43
		return _type;
44
	}
45
46
	/**
47
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
48
	 * 
49
	 * @return java.lang.String
50
	 */
51
	public java.lang.String getValue() {
52
		return _value;
53
	}
54
55
	public boolean isEnabled() {
56
		return _enabled;
57
	}
58
59
	/**
60
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
61
	 * 
62
	 * @param new_name
63
	 *            java.lang.String
64
	 */
65
	public void setName(java.lang.String new_name) {
66
		_name = new_name;
67
	}
68
69
	/**
70
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
71
	 * 
72
	 * @param new_type
73
	 *            java.lang.String
74
	 */
75
	public void setType(java.lang.String new_type) {
76
		_type = new_type;
77
	}
78
79
	/**
80
	 * Insert the method's description here. Creation date: (11/9/00 8:16:49 AM)
81
	 * 
82
	 * @param new_value
83
	 *            java.lang.String
84
	 */
85
	public void setValue(java.lang.String new_value) {
86
		_value = new_value;
87
	}
88
89
	public void setEnabled(boolean enabled) {
90
		_enabled = enabled;
91
	}
92
93
	public boolean equals(AgentConfigurationEntry rhs) {
94
		String rhsType = rhs.getType();
95
		String rhsName = rhs.getName();
96
		String rhsValue = rhs.getValue();
97
98
		/* Compare each of the strings. If anything is null then they are invalid entries and return not equal */
99
		try {
100
			/* Check if all the strings are the same */
101
			if (!(rhsType.equals(_type) && rhsName.equals(_name) && rhsValue.equals(_value))) {
102
				return false;
103
			}
104
		} catch (NullPointerException e) {
105
			return false;
106
		}
107
108
		return true;
109
	}
110
111
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentFactory.java (+47 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentFactory.java,v 1.3 2005/10/01 14:47:02 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class AgentFactory {
16
17
	/**
18
	 * Create a new agent instance with the specified name.
19
	 */
20
	public static Agent createAgent(Process process, String name) {
21
		return createAgent(process, name, null);
22
	}
23
24
	/**
25
	 * Create a new agent instance with the specified name and type.
26
	 */
27
	public static Agent createAgent(Process process, String name, String type) {
28
		Agent agent = null;
29
30
		/*
31
		 * Try to check if there is an agent already registered with the process
32
		 */
33
		agent = process.getAgent(name);
34
		if (agent != null) { // Assumption: Agent names must be unique within a process
35
			// Do nothing since the agent already exist
36
		} else {
37
			agent = new AgentImpl(process, name, type);
38
			try {
39
				((ProcessImpl) process).addAgent(agent);
40
				agent.addAgentListener((ProcessImpl) process);
41
			} catch (ClassCastException e) {
42
				/* Cannot set relationship unless process is a ProcessImpl */
43
			}
44
		}
45
		return agent;
46
	}
47
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ProcessListener.java (+27 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public interface ProcessListener {
16
17
	/**
18
	 * Invoked when a process is launched. The process parameter contains all the information regarding the process.
19
	 */
20
	void processLaunched(Process process);
21
22
	/**
23
	 * Invoked when a process that was previously launched exits.The process parameter contains all the information regarding the process.
24
	 */
25
	void processExited(Process process);
26
27
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentImpl.java (+796 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentImpl.java,v 1.18 2006/11/06 01:25:26 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.net.InetAddress;
17
import java.net.UnknownHostException;
18
import java.util.Enumeration;
19
import java.util.Vector;
20
21
import org.eclipse.hyades.execution.local.common.AgentQueryStateCommand;
22
import org.eclipse.hyades.execution.local.common.AttachToAgentCommand;
23
import org.eclipse.hyades.execution.local.common.CommandElement;
24
import org.eclipse.hyades.execution.local.common.Constants;
25
import org.eclipse.hyades.execution.local.common.ControlMessage;
26
import org.eclipse.hyades.execution.local.common.CustomCommand;
27
import org.eclipse.hyades.execution.local.common.DataProcessor;
28
import org.eclipse.hyades.execution.local.common.DetachFromAgentCommand;
29
import org.eclipse.hyades.execution.local.common.ErrorCommand;
30
import org.eclipse.hyades.execution.local.common.MonitorPeerRequestCommand;
31
import org.eclipse.hyades.execution.local.common.MonitorPeerRequestPortCommand;
32
import org.eclipse.hyades.execution.local.common.MultiplexedDataServer;
33
import org.eclipse.hyades.execution.local.common.RegisterAgentInterestCommand;
34
import org.eclipse.hyades.execution.local.common.SetNVPairCommand;
35
import org.eclipse.hyades.execution.local.common.StartMonitoringRemoteAgentCommand;
36
import org.eclipse.hyades.execution.local.common.StopMonitorCommand;
37
import org.eclipse.hyades.execution.local.common.TCPDataServer;
38
import org.eclipse.tptp.platform.agentcontroller.internal.DataConnection;
39
import org.eclipse.tptp.platform.agentcontroller.internal.impl.ConnectionFactoryImpl;
40
41
public class AgentImpl implements Agent, ProcessListener, ConnectionListener { // Bug 59316
42
	protected String _name = null;
43
	protected String _type = null;
44
	protected String _uuid = null;
45
	protected Process _process = null;
46
	protected AgentConfiguration _config;
47
	protected boolean _autoAttach = false;
48
	protected boolean _isMonitored = false;
49
	protected boolean _isActive = false;
50
	protected boolean _isAttached = false;
51
	protected TCPDataServer _server = null;
52
	protected MultiplexedDataServer _server_mux = null;
53
	protected String _profileFile = null;
54
	protected Vector _listeners = new Vector(10);
55
	private Object _lock = new Object();
56
	private boolean _isLocal = false;
57
58
	public static class UncheckedNotConnectedException extends RuntimeException {
59
60
		/**
61
		 * Stream-Unique IDentifier (SUID) of this class
62
		 */
63
		private static final long serialVersionUID = 3579779634351360004L;
64
	}
65
66
	public AgentImpl(Process process, String name) {
67
		this(process, name, null);
68
	}
69
70
	public AgentImpl(Process process, String name, String type) {
71
		this(process, name, type, false);
72
	}
73
74
	public AgentImpl(Process process, String name, String type, boolean active) {
75
		_process = process;
76
		_name = name;
77
		_type = type;
78
		_isActive = active;
79
		process.addProcessListener(this);
80
		try {
81
			Connection _connection = process.getNode().getConnection();
82
			if (_connection != null) {
83
				_connection.addConnectionListener(this); // Bug 59316
84
			} else {
85
				// bugzilla 79348 fix, throw NotConnectedException
86
				// if Connection is null for this node
87
				// In this case, the Agent was created before the node was
88
				// connected
89
				throw new UncheckedNotConnectedException();
90
			}
91
92
			// Check if this is running on the same machine as the agent
93
			if (_connection instanceof LocalConnectionImpl) {
94
				_isLocal = true;
95
				_connection.addConnectionListener(this);
96
			}
97
		} catch (InactiveProcessException e) {
98
		}
99
	}
100
101
	/**
102
	 * @see Agent#addAgentListener(AgentListener)
103
	 */
104
	public void addAgentListener(AgentListener listener) {
105
		synchronized (_listeners) {
106
			if (!_listeners.contains(listener)) {
107
				_listeners.add(listener);
108
			}
109
		}
110
	}
111
112
	/**
113
	 * @see Agent#removeAgentListener(AgentListener)
114
	 */
115
	public void removeAgentListener(AgentListener listener) {
116
		synchronized (_listeners) {
117
			if (_listeners.contains(listener)) {
118
				_listeners.remove(listener);
119
			}
120
		}
121
	}
122
123
	/**
124
	 * @see Agent#getProcess()
125
	 */
126
	public Process getProcess() {
127
		return _process;
128
	}
129
130
	/**
131
	 * @see Agent#setAutoAttach(boolean)
132
	 */
133
	public void setAutoAttach(boolean auto) {
134
		_autoAttach = auto;
135
		Process proc = getProcess();
136
137
		/*
138
		 * If the process is active we need to send our registration to the remote server
139
		 */
140
		if (proc != null) {
141
			if (proc.isActive()) {
142
				ControlMessage message = new ControlMessage();
143
				RegisterAgentInterestCommand command = new RegisterAgentInterestCommand();
144
				command.setAgentName(_name);
145
				try {
146
					command.setProcessId(new Long(proc.getProcessId()).longValue());
147
					message.appendCommand(command);
148
					proc.getNode().getConnection().sendMessage(message, new CommandHandler() {
149
						public void incommingCommand(Node node, CommandElement element) {
150
							handleCommand(element);
151
						}
152
					});
153
				} catch (InactiveProcessException e) {
154
					return;
155
				} catch (IOException e) {
156
				}
157
			}
158
		}
159
	}
160
161
	/**
162
	 * @see Agent#isAutoAttach(boolean)
163
	 */
164
	public boolean isAutoAttach() {
165
		return _autoAttach;
166
	}
167
168
	/**
169
	 * @see Agent#attach()
170
	 */
171
	public void attach() throws InactiveAgentException, InactiveProcessException {
172
		/*
173
		 * We will assume the attach is successful here. This is in fact incorrect but the transport layer must be changed to determine if an attach is in fact successful.
174
		 */
175
		setAttached(true);
176
177
		ControlMessage message = new ControlMessage();
178
		AttachToAgentCommand command = new AttachToAgentCommand();
179
		command.setAgentName(_name);
180
		command.setProcessId(Long.valueOf(getProcess().getProcessId()).longValue());
181
		message.appendCommand(command);
182
		try {
183
			_process.getNode().getConnection().sendMessage(message, new CommandHandler() {
184
				public void incommingCommand(Node node, CommandElement command) {
185
					handleCommand(command);
186
				}
187
			});
188
		} catch (IOException e) {
189
			/* We need to handle this */
190
		}
191
	}
192
193
	/**
194
	 * @see Agent#detach()
195
	 */
196
	public void detach() throws InactiveAgentException, InactiveProcessException {
197
		setAttached(false);
198
		stopMonitoring();
199
		_server = null; /* 9707 */
200
		_server_mux = null;
201
202
		ControlMessage message = new ControlMessage();
203
		DetachFromAgentCommand command = new DetachFromAgentCommand();
204
		command.setAgentName(_name);
205
		command.setProcessId(Long.valueOf(getProcess().getProcessId()).longValue());
206
		message.appendCommand(command);
207
		try {
208
			_process.getNode().getConnection().sendMessage(message, new CommandHandler() {
209
				public void incommingCommand(Node node, CommandElement command) {
210
					handleCommand(command);
211
				}
212
213
			});
214
		} catch (IOException e) {
215
			/* We need to handle this */
216
		}
217
	}
218
219
	/**
220
	 * @see Agent#getType()
221
	 */
222
	public String getType() {
223
		return _type;
224
	}
225
226
	/**
227
	 * @see Agent#getName()
228
	 */
229
	public String getName() {
230
		return _name;
231
	}
232
233
	/**
234
	 * @see Agent#getUUID()
235
	 */
236
	public String getUUID() {
237
		return _uuid;
238
	}
239
240
	/**
241
	 * @see Agent#isActive()
242
	 */
243
	public boolean isActive() {
244
		return _isActive;
245
	}
246
247
	/**
248
	 * @see Agent#isMonitored()
249
	 */
250
	public boolean isMonitored() {
251
		return _isMonitored;
252
	}
253
254
	// Bug 54376 begins
255
	/**
256
	 * @see Agent#isAttached()
257
	 */
258
	public boolean isAttached() {
259
		return isAttached(false);
260
	}
261
262
	/**
263
	 * @see Agent#isAttached()
264
	 */
265
	public boolean isAttached(boolean remote) {
266
		if (!remote) {
267
			return _isAttached;
268
		}
269
270
		ControlMessage message = new ControlMessage();
271
		AgentQueryStateCommand command = new AgentQueryStateCommand();
272
273
		synchronized (_lock) {
274
			try {
275
				command.setAgentName(_name);
276
				command.setProcessId(Long.valueOf(getProcess().getProcessId()).longValue());
277
				message.appendCommand(command);
278
				_process.getNode().getConnection().sendMessage(message, new CommandHandler() {
279
					public void incommingCommand(Node node, CommandElement command) {
280
						switch ((int) command.getTag()) {
281
						case (int) Constants.RA_AGENT_ATTACHED:
282
							setAttached(true);
283
							synchronized (_lock) {
284
								_lock.notify();
285
							}
286
							break;
287
						case (int) Constants.RA_AGENT_DETACHED:
288
							setAttached(false);
289
							synchronized (_lock) {
290
								_lock.notify();
291
							}
292
							break;
293
						}
294
					}
295
				});
296
				_lock.wait(5000); // 5 sec wait max
297
			} catch (InactiveProcessException e1) {
298
				// this should not occur
299
			} catch (IOException e2) {
300
				// this should not occur
301
			} catch (InterruptedException e3) {
302
				// this should not occur
303
			}
304
		}
305
306
		return _isAttached;
307
	}
308
309
	// Bug 54376 ends
310
311
	/**
312
	 * @see Agent#startMonitoring()
313
	 */
314
	public void startMonitoring(DataProcessor processor) throws InactiveAgentException {
315
		DataConnection dataConnection = null;
316
		int port = 0;
317
318
		if (!_isAttached) {
319
			return;
320
		}
321
322
		// Do not start the server threads if local
323
		if (_isLocal) {
324
			dataConnection = ConnectionFactoryImpl.createDirectDataConnection();
325
			port = -Integer.parseInt(dataConnection.getConnectionName());
326
			if (_server == null) {
327
				_server = new TCPDataServer(dataConnection);
328
				try {
329
					_server.startServer(processor);
330
				} catch (Exception e) {
331
					// TODO:
332
				}
333
			} else {
334
				_server.resumeServer(processor);
335
			}
336
		} else {
337
			dataConnection = ConnectionFactoryImpl.createSocketDataConnection();
338
			port = Integer.parseInt(dataConnection.getConnectionName());
339
340
			if (_server == null) {
341
				_server = new TCPDataServer(dataConnection);
342
				_server_mux = new MultiplexedDataServer();
343
				addAgentListener(_server_mux);
344
345
				/* 9707 */
346
				try {
347
					_server.startServer(processor);
348
					_server_mux.startServer(processor);
349
				} catch (Exception e) {
350
					// TODO:
351
				}
352
			} else {
353
				addAgentListener(_server_mux); /* 157656 */
354
				_server.resumeServer(processor); /* 9707 */
355
			}
356
		} // Remote
357
358
		ControlMessage message = new ControlMessage();
359
		StartMonitoringRemoteAgentCommand command = new StartMonitoringRemoteAgentCommand();
360
		command.setAgentName(_name);
361
362
		try {
363
			command.setInetAddress(InetAddress.getLocalHost());
364
		} catch (UnknownHostException e1) {
365
		}
366
367
		command.setPort((short) port);
368
		try {
369
			command.setProcessId(Long.parseLong(_process.getProcessId()));
370
			message.appendCommand(command);
371
			_process.getNode().getConnection().sendMessage(message, null);
372
		} catch (InactiveProcessException e) {
373
			throw new InactiveAgentException();
374
		} catch (IOException e) {
375
			/* We need to handle this */
376
		}
377
378
		setMonitored(true);
379
	}
380
381
	/**
382
	 * @see Agent#stopMonitoring()
383
	 */
384
	public void stopMonitoring() throws InactiveAgentException {
385
		if (_server != null) {
386
			_server.stopServer();
387
		}
388
389
		if (_server_mux != null) {
390
			removeAgentListener(_server_mux); /* 157656 */
391
		}
392
393
		if (!_isMonitored) {
394
			return;
395
		}
396
397
		ControlMessage message = new ControlMessage();
398
		StopMonitorCommand command = new StopMonitorCommand();
399
		command.setAgentName(_name);
400
		try {
401
			command.setProcessId(Long.parseLong(_process.getProcessId()));
402
			message.appendCommand(command);
403
			_process.getNode().getConnection().sendMessage(message, null);
404
		} catch (InactiveProcessException e) {
405
			throw new InactiveAgentException();
406
		} catch (IOException e) {
407
			/* We need to handle this */
408
		}
409
		setMonitored(false);
410
	}
411
412
	/**
413
	 * @see Agent#setConfiguration()
414
	 */
415
	public void setConfiguration(AgentConfiguration config) {
416
		_config = config;
417
	}
418
419
	/**
420
	 * @see Agent#getConfiguration
421
	 */
422
	public AgentConfiguration getConfiguration() {
423
		if (_config == null) {
424
			_config = new AgentConfiguration();
425
		}
426
		return _config;
427
	}
428
429
	/**
430
	 * @see Agent#publishConfiguration
431
	 */
432
	public void publishConfiguration() throws InactiveAgentException {
433
		if (!_isActive) {
434
			throw new InactiveAgentException();
435
		}
436
		if (_config == null) {
437
			return;
438
		}
439
		int entryCount = 0;
440
		ControlMessage message = new ControlMessage();
441
		synchronized (_config) {
442
			for (int i = 0; i < _config.size(); i++) {
443
				AgentConfigurationEntry entry = _config.getEntryAt(i);
444
				if (entry != null && entry.isEnabled()) {
445
					entryCount++;
446
					SetNVPairCommand command = new SetNVPairCommand();
447
					try {
448
						command.setProcessId(Long.parseLong(_process.getProcessId()));
449
					} catch (InactiveProcessException e) {
450
						throw new InactiveAgentException();
451
					}
452
					command.setAgentName(_name);
453
					command.setType(entry.getType());
454
					command.setName(entry.getName());
455
					command.setValue(entry.getValue());
456
					message.appendCommand(command);
457
				}
458
			}
459
		}
460
		if (entryCount > 0) {
461
			try {
462
				_process.getNode().getConnection().sendMessage(message, null);
463
			} catch (InactiveProcessException e) {
464
				throw new InactiveAgentException();
465
			} catch (IOException e) {
466
				/* We need to handle this */
467
			}
468
		}
469
	}
470
471
	/**
472
	 * @see Agent#invokeCustomCommand()
473
	 */
474
	public void invokeCustomCommand(CustomCommand command) throws InactiveAgentException {
475
		if (!_isActive) {
476
			throw new InactiveAgentException();
477
		}
478
		ControlMessage message = new ControlMessage();
479
		message.appendCommand(command);
480
		command.setAgentName(_name);
481
		try {
482
			command.setProcessId(Long.parseLong(_process.getProcessId()));
483
			_process.getNode().getConnection().sendMessage(message, new CommandHandler() {
484
				public void incommingCommand(Node node, CommandElement element) {
485
					handleCommand(element);
486
				}
487
			});
488
		} catch (InactiveProcessException e) {
489
			throw new InactiveAgentException();
490
		} catch (IOException e) {
491
			/* We need to handle this */
492
		}
493
	}
494
495
	public void setUUID(String uuid) {
496
		_uuid = uuid;
497
	}
498
499
	/**
500
	 * This is the local handler for
501
	 */
502
	public void handleCommand(final CommandElement command) {
503
		switch ((int) command.getTag()) {
504
		case (int) Constants.RA_AGENT_ACTIVE:
505
			synchronized (_listeners) {
506
				setActive(true);
507
				if (_autoAttach) {
508
					setAttached(true);
509
				}
510
				Enumeration elements = _listeners.elements();
511
				while (elements.hasMoreElements()) {
512
					((AgentListener) elements.nextElement()).agentActive(this);
513
				}
514
			}
515
			break;
516
		case (int) Constants.RA_AGENT_INACTIVE:
517
			synchronized (_listeners) {
518
				setActive(false);
519
				Enumeration elements = _listeners.elements();
520
				while (elements.hasMoreElements()) {
521
					((AgentListener) elements.nextElement()).agentInactive(this);
522
				}
523
				// _listeners.clear(); // clear listeners after agent becomes
524
				// inactive
525
			}
526
			break;
527
		case (int) Constants.RA_ERROR_STRING:
528
			synchronized (_listeners) {
529
				Enumeration elements = _listeners.elements();
530
				while (elements.hasMoreElements()) {
531
					((AgentListener) elements.nextElement()).error(this, ((ErrorCommand) command).getErrorId(), ((ErrorCommand) command).getErrorString());
532
				}
533
534
			}
535
			break;
536
		case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR:
537
		case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR_PORT: // Bug
538
			// 77768
539
			synchronized (_listeners) {
540
				/*
541
				 * We need to ensure we have the peer node/process/agent in our model
542
				 */
543
				try {
544
					InetAddress address = ((MonitorPeerRequestCommand) command).getPeerNode();
545
					if (address != null) {
546
						final Node node = NodeFactory.createNode(address.getHostAddress());
547
548
						/*
549
						 * RKD: We shouldn't do the connect here. This should be delegated to the listener so that the proper connection can be opened and the appropriate authenticationListeners can be added to the connection.
550
						 */
551
						if (!node.isConnected()) {
552
							/* Bug 77768 begins */
553
							int port;
554
							if (command.getTag() == (int) Constants.RA_CONTROLLER_REQUEST_MONITOR_PORT) {
555
								port = (int) ((MonitorPeerRequestPortCommand) command).getTargetPort();
556
							} else {
557
								port = (int) Constants.CTL_PORT_NUM_SERVER;
558
							}
559
							node.connect(port);
560
							/* Bug 77768 ends */
561
						}
562
563
						final Agent agent = this;
564
565
						/*
566
						 * My initial plan was to call list processes here but that blocks the calling thread until the background processing is done. The problem with this is that the background thread is this thread..so we deadlock. So the new plan is to create another thread to do the remainder of the notification.
567
						 */
568
569
						Runnable delegate = new Runnable() {
570
							public void run() {
571
572
								/* Refresh our process list on the node */
573
								String peerProcessId = Long.toString(((MonitorPeerRequestCommand) command).getProcessId());
574
								Enumeration processes = null;
575
576
								try {
577
									processes = node.listProcesses();
578
								} catch (NotConnectedException e) {
579
									/*
580
									 * We are the connnection thread so this cannot happen
581
									 */
582
								}
583
584
								Process proc = null;
585
								while (processes.hasMoreElements()) {
586
									proc = (Process) processes.nextElement();
587
									try {
588
										if (proc.getProcessId().equals(peerProcessId)) {
589
											break;
590
										}
591
										proc = null;
592
									} catch (InactiveProcessException e) {
593
										/* Ignore inactive processes */
594
									}
595
596
								}
597
598
								/*
599
								 * The process may have exited. Onceagainwe should probably inform the requesting Agent Controller
600
								 */
601
								if (proc == null) {
602
									return;
603
								}
604
605
								Agent peer = proc.getAgent(((MonitorPeerRequestCommand) command).getAgentName());
606
607
								if (peer == null) {
608
									return;
609
								}
610
611
								/* Inform the listeners */
612
								Enumeration elements = _listeners.elements();
613
								while (elements.hasMoreElements()) {
614
									AgentListener listener = ((AgentListener) elements.nextElement());
615
									if (listener instanceof AgentPeerListener) {
616
										((AgentPeerListener) listener).peerWaiting(agent, peer);
617
									}
618
								}
619
							}
620
						};
621
622
						Thread newThread = new Thread(delegate, "PeerDelegate");
623
						newThread.start();
624
					}
625
				} catch (UnknownHostException e) {
626
					/*
627
					 * We can't resolve the target host, for now we will break. We may need to send an error message back to the forwarding RAC.
628
					 */
629
					break;
630
				} catch (AgentControllerUnavailableException e) {
631
					/*
632
					 * We cannot reach the RAC on this machine, this hould only occur as a result of bad name resolution as the RAC requested a connect.
633
					 */
634
				}
635
636
			}
637
			break;
638
		case (int) Constants.RA_PROCESS_EXITED:
639
			/*
640
			 * Beacuse of context mappings we may directly hear that this process has exited rather then the command being routed to the process. This is because context on the server side is held in the agent.
641
			 */
642
			try {
643
				ProcessImpl process = (ProcessImpl) this.getProcess();
644
				if (process != null) { // Bug 110941
645
					processExited(process); // Do this first before cleaning up the Process instance
646
					process.handleCommand(command);
647
				}
648
			} catch (ClassCastException e) {
649
				/* We can ignore this */
650
			}
651
			break;
652
		default:
653
			synchronized (_listeners) {
654
				Enumeration elements = _listeners.elements();
655
				while (elements.hasMoreElements()) {
656
					((AgentListener) elements.nextElement()).handleCommand(this, command);
657
				}
658
659
			}
660
		}
661
	}
662
663
	private void cleanup() {
664
665
		// Remove process listener and clean-up (leaks memory without this
666
		// clean-up)
667
		if (this._process != null) {
668
			try {
669
				_process.getNode().getConnection().removeConnectionListener(this); // Bug
670
				// 59316
671
			} catch (InactiveProcessException e) {
672
			}
673
			_process = null;
674
		}
675
		if (this._listeners != null) {
676
			this._listeners.clear();
677
		}
678
679
		// Null out the server instance variables
680
		_server = null;
681
		_server_mux = null;
682
683
	}
684
685
	/**
686
	 * @see ProcessListener#processLaunched
687
	 */
688
	public void processLaunched(Process process) {
689
	}
690
691
	/**
692
	 * @see ProcessListener#processExited
693
	 */
694
	public void processExited(Process process) {
695
		/*
696
		 * It may be that the process dies unexpectantly and the agent believes it is still active.
697
		 */
698
699
		if (_server != null) {
700
			_server.shutdownServer();
701
		}
702
		if (_server_mux != null) {
703
			_server_mux.shutdownServer();
704
		}
705
		_server = null;
706
		_server_mux = null;
707
708
		// Bug 59316 begins
709
		/*
710
		 * This has to be done no matter _server exists or not since the client might just attach to the agent but doesn't start monitoring (so that _server is not created.
711
		 */
712
		if (process == _process && _isActive) {
713
			synchronized (_listeners) {
714
				setActive(false);
715
				Enumeration elements = _listeners.elements();
716
				while (elements.hasMoreElements()) {
717
					((AgentListener) elements.nextElement()).agentInactive(this);
718
				}
719
			}
720
		}
721
		// Bug 59316 ends
722
		this.cleanup();
723
	}
724
725
	/**
726
	 * Determine if this agent is sending data to a profiling file
727
	 */
728
	public boolean isToProfileFile() {
729
		return (_profileFile != null && _profileFile.trim().length() != 0);
730
	}
731
732
	/**
733
	 * Get the fully quality path of profiling file
734
	 * 
735
	 * @return String
736
	 */
737
	public String getProfileFile() {
738
		return _profileFile;
739
	}
740
741
	/**
742
	 * Set the fully quality path of profiling file
743
	 * 
744
	 * @param _profileFile
745
	 *            The _profileFile to set
746
	 */
747
	public void setProfileFile(String _profileFile) {
748
		this._profileFile = _profileFile;
749
	}
750
751
	// Bug 59316 begins
752
	public void connectionClosed(Connection connection) {
753
		synchronized (_listeners) {
754
			setActive(false);
755
			Enumeration elements = _listeners.elements();
756
			while (elements.hasMoreElements()) {
757
				((AgentListener) elements.nextElement()).agentInactive(this);
758
			}
759
		}
760
	}
761
762
	// Bug 59316 ends
763
764
	/**
765
	 * Additional setters and getters
766
	 */
767
	public void setProcess(Process p) {
768
		_process = p;
769
	}
770
771
	public void setType(String type) {
772
		_type = type;
773
	}
774
775
	public void setName(String name) {
776
		_name = name;
777
	}
778
779
	public void setActive(boolean isActive) {
780
		_isActive = isActive;
781
782
		if (!isActive) {
783
			setMonitored(false);
784
			setAttached(false);
785
		}
786
	}
787
788
	public void setMonitored(boolean isMonitored) {
789
		_isMonitored = isMonitored;
790
	}
791
792
	public void setAttached(boolean isAttached) {
793
		_isAttached = isAttached;
794
	}
795
796
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/LaunchProcessCommand.java (+187 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LaunchProcessCommand.java,v 1.5 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.util.Vector;
16
17
public class LaunchProcessCommand extends CommandElement implements Constants {
18
	private long _consoleIP = 0; // Note: for local direct connetion, this is set to 0
19
	private long _consolePort = 0; // Note: for local direct connetion, this is set to the instance number
20
	private RAString _exe = new RAString("");
21
	private RAString _args = new RAString("");
22
	private RAString _location = new RAString("");
23
	private Vector _environment = new Vector();
24
	private Vector _agents = new Vector();
25
26
	public LaunchProcessCommand() {
27
		super();
28
		_tag = RA_LAUNCH_PROCESS;
29
	}
30
31
	public void addAgent(String name) {
32
		_agents.addElement(new RAString(name));
33
	}
34
35
	public void addEnvironmentVariable(String name, String value) {
36
		_environment.addElement(new RAString(name + "=" + value));
37
	}
38
39
	public String getArgs() {
40
		if (_args != null) {
41
			return _args.getData();
42
		} else {
43
			return null;
44
		}
45
	}
46
47
	public long getConsoleIP() {
48
		return _consoleIP;
49
	}
50
51
	public long getConsolePort() {
52
		return _consolePort;
53
	}
54
55
	public String getExe() {
56
		if (_exe != null) {
57
			return _exe.getData();
58
		} else {
59
			return null;
60
		}
61
	}
62
63
	public String getLocation() {
64
		if (_location != null) {
65
			return _location.getData();
66
		} else {
67
			return null;
68
		}
69
	}
70
71
	public Vector getEnvironment() {
72
		if (_environment != null) {
73
			return _environment;
74
		} else {
75
			return null;
76
		}
77
	}
78
79
	public Vector getAgents() {
80
		if (_agents != null) {
81
			return _agents;
82
		} else {
83
			return null;
84
		}
85
	}
86
87
	public int getSize() {
88
		int size = super.getSize();
89
90
		size += sizeofLong; // consoleIP
91
		size += sizeofLong; // consolePort
92
		size += +_exe.getSize();
93
		size += _args.getSize();
94
		size += _location.getSize();
95
96
		size += sizeofLong; // list size
97
		for (int i = 0; i < _environment.size(); i++) {
98
			size += ((RAString) _environment.elementAt(i)).getSize();
99
		}
100
101
		size += sizeofLong; // list size
102
		for (int i = 0; i < _agents.size(); i++) {
103
			size += ((RAString) _agents.elementAt(i)).getSize();
104
		}
105
106
		return size;
107
	}
108
109
	public int readFromBuffer(byte[] buffer, int offset) {
110
		int current = offset;
111
112
		current = super.readFromBuffer(buffer, current);
113
114
		_consoleIP = Message.readRALongFromBuffer(buffer, current);
115
		current += sizeofLong;
116
117
		_consolePort = Message.readRALongFromBuffer(buffer, current);
118
		current += sizeofLong;
119
120
		current = Message.readRAStringFromBuffer(buffer, current, _exe);
121
		current = Message.readRAStringFromBuffer(buffer, current, _args);
122
		current = Message.readRAStringFromBuffer(buffer, current, _location);
123
124
		long listLength = Message.readRALongFromBuffer(buffer, current);
125
		current += sizeofLong;
126
		for (int i = 0; i < listLength; i++) {
127
			RAString envVar = new RAString();
128
			current = Message.readRAStringFromBuffer(buffer, current, envVar);
129
			_environment.addElement(envVar);
130
		}
131
132
		listLength = Message.readRALongFromBuffer(buffer, current);
133
		current += sizeofLong;
134
		for (int i = 0; i < listLength; i++) {
135
			RAString envVar = new RAString();
136
			current = Message.readRAStringFromBuffer(buffer, current, envVar);
137
			_agents.addElement(envVar);
138
		}
139
140
		return current;
141
142
	}
143
144
	public void setArgs(String args) {
145
		_args = new RAString(args);
146
	}
147
148
	public void setConsole(Console console) throws ConsoleNotStartedException {
149
		_consoleIP = console.getIP();
150
		_consolePort = console.getPort();
151
	}
152
153
	public void setConsole(long id) {
154
		_consoleIP = 0;
155
		_consolePort = id;
156
	}
157
158
	public void setExe(String exe) {
159
		_exe = new RAString(exe);
160
	}
161
162
	public void setLocation(String location) {
163
		_location = new RAString(location);
164
	}
165
166
	public int writeToBuffer(byte[] buffer, int offset) {
167
		int current = offset;
168
169
		current = super.writeToBuffer(buffer, current);
170
		current = Message.writeRALongToBuffer(buffer, current, _consoleIP);
171
		current = Message.writeRALongToBuffer(buffer, current, _consolePort);
172
		current = Message.writeRAStringToBuffer(buffer, current, _exe);
173
		current = Message.writeRAStringToBuffer(buffer, current, _args);
174
		current = Message.writeRAStringToBuffer(buffer, current, _location);
175
176
		current = Message.writeRALongToBuffer(buffer, current, (long) _environment.size());
177
		for (int i = 0; i < _environment.size(); i++) {
178
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) _environment.elementAt(i)));
179
		}
180
		current = Message.writeRALongToBuffer(buffer, current, (long) _agents.size());
181
		for (int i = 0; i < _agents.size(); i++) {
182
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) _agents.elementAt(i)));
183
		}
184
185
		return current;
186
	}
187
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/StopMonitorCommand.java (+29 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: StopMonitorCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
/**
16
 * Insert the type's description here. Creation date: (7/21/00 2:02:57 PM)
17
 * 
18
 * @author: Richard K. Duggan
19
 */
20
public class StopMonitorCommand extends SimpleAgentInfoCommand {
21
22
	/**
23
	 * StopMonitorCommand constructor comment.
24
	 */
25
	public StopMonitorCommand() {
26
		super();
27
		_tag = RA_STOP_MONITORING_AGENT;
28
	}
29
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ConnectionListener.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ConnectionListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public interface ConnectionListener {
16
17
	/**
18
	 * Invoked when a connection is lost. A connection could be lost due to any number of errors.
19
	 */
20
	void connectionClosed(Connection connection);
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/InactiveAgentException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: InactiveAgentException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class InactiveAgentException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 3237062246917142810L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentActiveCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentActiveCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentActiveCommand extends DetailedAgentInfoCommand {
16
17
	/**
18
	 * ReadyVMCommand constructor comment.
19
	 */
20
	public AgentActiveCommand() {
21
		super();
22
		_tag = RA_AGENT_ACTIVE;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/core/file/socket/ISocketChannel.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ISocketChannel.java,v 1.1 2005/09/21 20:51:31 sschneid Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.hyades.execution.core.file.socket;
14
15
import java.net.Socket;
16
import java.nio.channels.Channel;
17
import java.nio.channels.ReadableByteChannel;
18
import java.nio.channels.WritableByteChannel;
19
20
/**
21
 * An abstraction above the socket channel to allow a socket channel to be
22
 * emulated by taking a readable byte channel and a writeable byte channel and
23
 * combining them into a new interface. Socket channel is a class and not an
24
 * interface in Java, so this interface is introduced to satisfy our purposes.
25
 * 
26
 * The file transfer service will work with this socket channel interface
27
 * instead of directing using Java's standard socket channel class.
28
 * 
29
 * @author Scott E. Schneider
30
 */
31
public interface ISocketChannel extends Channel, ReadableByteChannel, WritableByteChannel {
32
	/**
33
	 * Returns the underlying socket associated with this channel
34
	 * 
35
	 * @return the socket associated with this channel
36
	 */
37
	public Socket getSocket();
38
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentListener.java (+39 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import org.eclipse.hyades.execution.local.common.CommandElement;
16
17
public interface AgentListener {
18
19
	/**
20
	 * Invoked when an agent first becomes active
21
	 */
22
	void agentActive(Agent agent);
23
24
	/**
25
	 * Invoked when an agent becomes inactive.
26
	 */
27
	void agentInactive(Agent agent);
28
29
	/**
30
	 * Invoked when an error is recieved from the agent.
31
	 */
32
	void error(Agent agent, String errorId, String errorMessage);
33
34
	/**
35
	 * Invoked when there is no established handler for the context of a message.
36
	 */
37
	void handleCommand(Agent agent, CommandElement command);
38
39
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/SetNVPairCommand.java (+118 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SetNVPairCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class SetNVPairCommand extends SimpleAgentInfoCommand {
16
17
	protected RAString _type = new RAString("");
18
	protected RAString _name = new RAString("");
19
	protected RAString _value = new RAString("");
20
21
	/**
22
	 * SetNVPairCommand constructor comment.
23
	 */
24
	public SetNVPairCommand() {
25
		super();
26
		_tag = RA_SET_NAME_VALUE_PAIR;
27
	}
28
29
	/**
30
	 * Insert the method's description here. Creation date: (11/2/00 7:52:45 PM)
31
	 * 
32
	 * @return java.lang.String
33
	 */
34
	public String getName() {
35
		return _name.getData();
36
	}
37
38
	/**
39
	 * getSize method comment.
40
	 */
41
	public int getSize() {
42
		int size = super.getSize();
43
		size += _type.getSize();
44
		size += _name.getSize();
45
		size += _value.getSize();
46
		return size;
47
	}
48
49
	/**
50
	 * Insert the method's description here. Creation date: (11/2/00 7:53:15 PM)
51
	 * 
52
	 * @return java.lang.String
53
	 */
54
	public String getType() {
55
		return _type.getData();
56
	}
57
58
	/**
59
	 * Insert the method's description here. Creation date: (11/2/00 7:53:42 PM)
60
	 * 
61
	 * @return java.lang.String
62
	 */
63
	public String getValue() {
64
		return _value.getData();
65
	}
66
67
	/**
68
	 * readFromBuffer method comment.
69
	 */
70
	public int readFromBuffer(byte[] buffer, int offset) {
71
		int current = super.readFromBuffer(buffer, offset);
72
		current = Message.readRAStringFromBuffer(buffer, current, _type);
73
		current = Message.readRAStringFromBuffer(buffer, current, _name);
74
		current = Message.readRAStringFromBuffer(buffer, current, _value);
75
		return current;
76
	}
77
78
	/**
79
	 * Insert the method's description here. Creation date: (11/2/00 7:55:20 PM)
80
	 * 
81
	 * @param name
82
	 *            java.lang.String
83
	 */
84
	public void setName(String name) {
85
		_name.setData(name);
86
	}
87
88
	/**
89
	 * Insert the method's description here. Creation date: (11/2/00 7:54:59 PM)
90
	 * 
91
	 * @param type
92
	 *            java.lang.String
93
	 */
94
	public void setType(String type) {
95
		_type.setData(type);
96
	}
97
98
	/**
99
	 * Insert the method's description here. Creation date: (11/2/00 7:55:53 PM)
100
	 * 
101
	 * @param value
102
	 *            java.lang.String
103
	 */
104
	public void setValue(String value) {
105
		_value.setData(value);
106
	}
107
108
	/**
109
	 * writeToBuffer method comment.
110
	 */
111
	public int writeToBuffer(byte[] buffer, int offset) {
112
		int current = super.writeToBuffer(buffer, offset);
113
		current = Message.writeRAStringToBuffer(buffer, current, _type);
114
		current = Message.writeRAStringToBuffer(buffer, current, _name);
115
		current = Message.writeRAStringToBuffer(buffer, current, _value);
116
		return current;
117
	}
118
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentControllerUnavailableException.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentControllerUnavailableException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import org.eclipse.hyades.execution.core.DaemonConnectException;
16
17
public class AgentControllerUnavailableException extends DaemonConnectException {
18
19
	/**
20
	 * Stream-Unique IDentifier (SUID) of this class
21
	 */
22
	private static final long serialVersionUID = -4914319348525595629L;
23
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/CustomCommand.java (+134 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CustomCommand.java,v 1.4 2005/06/09 19:43:05 bjiang Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class CustomCommand extends SimpleAgentInfoCommand {
16
17
	public static final String ENCODING = "UTF-8";
18
	protected RAString _data = null;
19
	protected RABinaryArray _binaryData = null;
20
21
	/**
22
	 * CustomCommand constructor comment.
23
	 */
24
	public CustomCommand() {
25
		super();
26
		_tag = RA_CUSTOM_COMMAND;
27
	}
28
29
	/**
30
	 * Insert the method's description here. Creation date: (2/20/01 11:23:17
31
	 * PM)
32
	 * 
33
	 * @return java.lang.String
34
	 */
35
	public String getData() {
36
		if (_data != null) {
37
			return _data.getData();
38
		} else if (_binaryData != null) {
39
			/*
40
			 * bugzilla 70251 - string data is send over the wire in UTF-8 so
41
			 * read bytes as UTF-8
42
			 */
43
			try {
44
				return new String(_binaryData.getData(), ENCODING);
45
			} catch (Exception e) {
46
				return new String(_binaryData.getData());
47
			}
48
		}
49
		return null;
50
	}
51
52
	public byte[] getDataBinary() {
53
		if (_binaryData != null) {
54
			return _binaryData.getData();
55
		} else if (_data != null) {
56
			try {
57
				return _data.getData().getBytes(ENCODING);
58
			} catch (Exception e) {
59
			}
60
		}
61
		return null;
62
	}
63
64
	/**
65
	 * getSize method comment.
66
	 */
67
	public int getSize() {
68
		if (_data != null) {
69
			return super.getSize() + _data.getSize();
70
		} else if (_binaryData != null) {
71
			return super.getSize() + _binaryData.getSize();
72
		}
73
		/* If neither of these are set, the minimum size is sizeofLong */
74
		return super.getSize() + sizeofLong;
75
	}
76
77
	/**
78
	 * readFromBuffer method comment.
79
	 */
80
	public int readFromBuffer(byte[] buffer, int offset) {
81
		int current = super.readFromBuffer(buffer, offset);
82
		_binaryData = new RABinaryArray();
83
		current = Message.readRABinaryArrayFromBuffer(buffer, current, _binaryData);
84
		return current;
85
	}
86
87
	/**
88
	 * Insert the method's description here. Creation date: (11/2/00 8:20:52 PM)
89
	 * 
90
	 * @param data
91
	 *            java.lang.String
92
	 */
93
	public void setData(String data) {
94
		if (_data == null) {
95
			_data = new RAString(data);
96
		} else {
97
			_data.setData(data);
98
		}
99
		_binaryData = null;
100
101
	}
102
103
	public void setData(byte[] data) {
104
		if (_binaryData == null) {
105
			_binaryData = new RABinaryArray(data);
106
		} else {
107
			_binaryData.setData(data);
108
		}
109
		_data = null;
110
	}
111
112
	/**
113
	 * writeToBuffer method comment.
114
	 */
115
	public int writeToBuffer(byte[] buffer, int offset) {
116
		int current;
117
		if (_data != null) {
118
			current = super.writeToBuffer(buffer, offset);
119
			current = Message.writeRAStringToBuffer(buffer, current, _data);
120
		} else if (_binaryData != null) {
121
			// By eliminating the change to the tag, the command type will
122
			// remain unchanged, causing encoding problems
123
			// on platforms such as the 390 if custom commands are used
124
			// inproperly as binary custom commands.
125
			// _tag=RA_BINARY_CUSTOM_COMMAND;
126
			current = super.writeToBuffer(buffer, offset);
127
			current = Message.writeRABinaryArrayToBuffer(buffer, current, _binaryData);
128
		} else {
129
			current = super.writeToBuffer(buffer, offset);
130
			current = Message.writeRAStringToBuffer(buffer, current, new RAString(""));
131
		}
132
		return current;
133
	}
134
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ServerSecurityInfoCommand.java (+74 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ServerSecurityInfoCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class ServerSecurityInfoCommand extends CommandElement implements Constants {
16
	private long _flag;
17
	private long _port;
18
19
	public ServerSecurityInfoCommand() {
20
		super();
21
		_tag = RA_SERVER_SECURITY_REQUIREMENTS;
22
	}
23
24
	public int getSize() {
25
		int size = super.getSize();
26
27
		size += sizeofLong; // flag
28
		size += sizeofLong; // port
29
30
		return size;
31
	}
32
33
	public long getSecurePort() {
34
		return _port;
35
	}
36
37
	public boolean isPasswordProtected() {
38
		return _flag < 3;
39
	}
40
41
	public boolean isClientAuthenticationRequired() {
42
		return _flag > 1;
43
	}
44
45
	public int readFromBuffer(byte[] buffer, int offset) {
46
		int current = offset;
47
48
		/*
49
		 * Cannot call super.readFromBuffer() since this command does not have a context
50
		 */
51
		// current = super.readFromBuffer(buffer, current);
52
		_flag = Message.readRALongFromBuffer(buffer, current);
53
		current += sizeofLong;
54
55
		_port = Message.readRALongFromBuffer(buffer, current);
56
		current += sizeofLong;
57
58
		return current;
59
	}
60
61
	public int writeToBuffer(byte[] buffer, int offset) {
62
		int current = offset;
63
64
		/*
65
		 * Cannot call super.writeToBuffer() since this command does not have a context
66
		 */
67
		// current = super.writeToBuffer(buffer, current);
68
		current = Message.writeRALongToBuffer(buffer, current, _tag);
69
		current = Message.writeRALongToBuffer(buffer, current, _flag);
70
		current = Message.writeRALongToBuffer(buffer, current, _port);
71
72
		return current;
73
	}
74
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentConfigurationCommand.java (+187 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentConfigurationCommand.java,v 1.3 2006/03/06 19:49:40 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.util.Vector;
16
17
import org.eclipse.hyades.execution.local.control.AgentConfigurationEntry;
18
19
public class AgentConfigurationCommand extends CommandElement implements Constants {
20
	private long processId = 0;
21
	private RAString processUUID = new RAString();
22
	private RAString agentName = new RAString();
23
	private RAString agentUUID = new RAString();
24
	private RAString agentType = new RAString();
25
	private RAString nodeUUID = new RAString();
26
	private Vector entries = new Vector();
27
28
	public AgentConfigurationCommand() {
29
		_tag = Constants.RA_AGENT_CONFIGURATION;
30
	}
31
32
	public int getSize() {
33
		int size = 0;
34
35
		size += super.getSize();
36
37
		size += sizeofLong; // processId
38
39
		size += processUUID.getSize();
40
		size += agentName.getSize();
41
		size += agentUUID.getSize();
42
		size += agentType.getSize();
43
		size += nodeUUID.getSize();
44
45
		size += sizeofLong; // num of entries
46
		for (int i = 0; i < entries.size(); i++) {
47
			RAString name = new RAString(((AgentConfigurationEntry) entries.elementAt(i)).getName());
48
			RAString type = new RAString(((AgentConfigurationEntry) entries.elementAt(i)).getType());
49
			RAString value = new RAString(((AgentConfigurationEntry) entries.elementAt(i)).getValue());
50
51
			size += name.getSize();
52
			size += type.getSize();
53
			size += value.getSize();
54
		}
55
56
		return size;
57
	}
58
59
	public int readFromBuffer(byte[] buffer, int offset) {
60
		int current = offset;
61
		long numConfig;
62
63
		current = super.readFromBuffer(buffer, current);
64
65
		processId = Message.readRALongFromBuffer(buffer, current);
66
		current += sizeofLong;
67
68
		current = Message.readRAStringFromBuffer(buffer, current, processUUID);
69
		current = Message.readRAStringFromBuffer(buffer, current, agentName);
70
		current = Message.readRAStringFromBuffer(buffer, current, agentUUID);
71
		current = Message.readRAStringFromBuffer(buffer, current, agentType);
72
		current = Message.readRAStringFromBuffer(buffer, current, nodeUUID);
73
74
		numConfig = Message.readRALongFromBuffer(buffer, current);
75
		current += sizeofLong;
76
77
		for (int i = 0; i < numConfig; i++) {
78
			RAString type = new RAString();
79
			RAString name = new RAString();
80
			RAString value = new RAString();
81
82
			current = Message.readRAStringFromBuffer(buffer, current, type);
83
			current = Message.readRAStringFromBuffer(buffer, current, name);
84
			current = Message.readRAStringFromBuffer(buffer, current, value);
85
86
			AgentConfigurationEntry entry = new AgentConfigurationEntry();
87
			entry.setType(type.getData());
88
			entry.setName(name.getData());
89
			entry.setValue(value.getData());
90
91
			addEntry(entry);
92
		}
93
94
		return current;
95
	}
96
97
	public int writeToBuffer(byte[] buffer, int offset) {
98
		int current = offset;
99
100
		current = super.writeToBuffer(buffer, current);
101
		current = Message.writeRALongToBuffer(buffer, current, processId);
102
		current = Message.writeRAStringToBuffer(buffer, current, processUUID);
103
		current = Message.writeRAStringToBuffer(buffer, current, agentName);
104
		current = Message.writeRAStringToBuffer(buffer, current, agentUUID);
105
		current = Message.writeRAStringToBuffer(buffer, current, agentType);
106
		current = Message.writeRAStringToBuffer(buffer, current, nodeUUID);
107
		current = Message.writeRALongToBuffer(buffer, current, entries.size());
108
		for (int i = 0; i < entries.size(); i++) {
109
			AgentConfigurationEntry entry = (AgentConfigurationEntry) entries.elementAt(i);
110
			current = Message.writeRAStringToBuffer(buffer, current, new RAString(entry.getType()));
111
			current = Message.writeRAStringToBuffer(buffer, current, new RAString(entry.getName()));
112
			current = Message.writeRAStringToBuffer(buffer, current, new RAString(entry.getValue()));
113
		}
114
115
		return current;
116
	}
117
118
	public void clear() {
119
		entries.clear();
120
	}
121
122
	public AgentConfigurationEntry[] getConfigurations() {
123
		return (AgentConfigurationEntry[]) entries.toArray();
124
	}
125
126
	public void addEntry(AgentConfigurationEntry entry) {
127
		this.entries.add(entry);
128
	}
129
130
	public boolean removeEntry(AgentConfigurationEntry entry) {
131
		if (entries.contains(entry)) {
132
			entries.remove(entry);
133
			return true;
134
		} else {
135
			return false;
136
		}
137
	}
138
139
	public RAString getAgentName() {
140
		return agentName;
141
	}
142
143
	public void setAgentName(RAString agentName) {
144
		this.agentName = agentName;
145
	}
146
147
	public RAString getAgentType() {
148
		return agentType;
149
	}
150
151
	public void setAgentType(RAString agentType) {
152
		this.agentType = agentType;
153
	}
154
155
	public RAString getAgentUUID() {
156
		return agentUUID;
157
	}
158
159
	public void setAgentUUID(RAString agentUUID) {
160
		this.agentUUID = agentUUID;
161
	}
162
163
	public RAString getNodeUUID() {
164
		return nodeUUID;
165
	}
166
167
	public void setNodeUUID(RAString nodeUUID) {
168
		this.nodeUUID = nodeUUID;
169
	}
170
171
	public long getProcessId() {
172
		return processId;
173
	}
174
175
	public void setProcessId(long processId) {
176
		this.processId = processId;
177
	}
178
179
	public RAString getProcessUUID() {
180
		return processUUID;
181
	}
182
183
	public void setProcessUUID(RAString processUUID) {
184
		this.processUUID = processUUID;
185
	}
186
187
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ActiveAgentListCommand.java (+94 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ActiveAgentListCommand.java,v 1.3 2005/09/27 20:31:56 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.util.Vector;
16
17
public class ActiveAgentListCommand extends SimpleProcessCommand {
18
19
	protected Vector _agents = new Vector();
20
	protected RAString _processName = new RAString("");
21
22
	/**
23
	 * ActiveAgentListCommand constructor comment.
24
	 */
25
	public ActiveAgentListCommand() {
26
		super();
27
		_tag = RA_AGENT_LIST;
28
	}
29
30
	public ActiveAgentListCommand(String processName, Vector agents) {
31
		super();
32
		_tag = RA_AGENT_LIST;
33
34
		_processName = new RAString(processName);
35
		_agents = agents;
36
	}
37
38
	public String[] getAgents() {
39
		int length = _agents.size();
40
		String[] results = new String[length];
41
		for (int i = 0; i < length; i++) {
42
			results[i] = ((RAString) _agents.elementAt(i)).getData();
43
		}
44
		return results;
45
	}
46
47
	public String getProcessName() {
48
		return _processName.getData();
49
50
	}
51
52
	/**
53
	 * getSize method comment.
54
	 */
55
	public int getSize() {
56
		int size = super.getSize();
57
		size += _processName.getSize();
58
		size += sizeofLong;
59
		for (int i = 0; i < _agents.size(); i++) {
60
			size += ((RAString) _agents.elementAt(i)).getSize();
61
		}
62
		return size;
63
	}
64
65
	/**
66
	 * readFromBuffer method comment.
67
	 */
68
	public int readFromBuffer(byte[] buffer, int offset) {
69
		int current = super.readFromBuffer(buffer, offset);
70
		current = Message.readRAStringFromBuffer(buffer, current, _processName);
71
		long listLength = Message.readRALongFromBuffer(buffer, current);
72
		current += sizeofLong;
73
		for (int i = 0; i < listLength; i++) {
74
			RAString agent = new RAString("");
75
			current = Message.readRAStringFromBuffer(buffer, current, agent);
76
			_agents.addElement(agent);
77
		}
78
		return current;
79
	}
80
81
	/**
82
	 * writeToBuffer method comment.
83
	 */
84
	public int writeToBuffer(byte[] buffer, int offset) {
85
		int current = super.writeToBuffer(buffer, offset);
86
		current = Message.writeRAStringToBuffer(buffer, current, _processName);
87
		current = Message.writeRALongToBuffer(buffer, current, _agents.size());
88
		for (int i = 0; i < _agents.size(); i++) {
89
			current = Message.writeRAStringToBuffer(buffer, current, ((RAString) _agents.elementAt(i)));
90
		}
91
		return current;
92
	}
93
94
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AcknowledgementHandler.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AcknowledgementHandler.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
17
public interface AcknowledgementHandler {
18
19
	void incommingAcknowledgement(InetAddress server, long ticket);
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentDetachedCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentDetachedCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentDetachedCommand extends SimpleAgentInfoCommand { // Bug 54376
16
17
	/**
18
	 * Constructor
19
	 */
20
	public AgentDetachedCommand() {
21
		super();
22
		_tag = RA_AGENT_DETACHED;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ControlServerDaemon.java (+143 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ControlServerDaemon.java,v 1.4 2005/09/13 16:46:20 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.IOException;
16
import java.net.DatagramPacket;
17
import java.net.DatagramSocket;
18
import java.net.InetAddress;
19
import java.net.SocketException;
20
21
public class ControlServerDaemon implements Constants {
22
23
	private DatagramServer _server = null;
24
	private DatagramSocket _sock = null;
25
	private AcknowledgementHandler _ackHandler = null;
26
	private CommandHandler _cmdHandler = null;
27
28
	class DatagramServer extends Thread implements Constants {
29
		DatagramSocket _socket = null;
30
31
		public void setSocket(DatagramSocket sock) {
32
			_socket = sock;
33
		}
34
35
		public void run() {
36
37
			/* Run forever */
38
			while (true) {
39
				byte[] buffer = new byte[MAX_MESSAGE_LENGTH];
40
				DatagramPacket data = new DatagramPacket(buffer, MAX_MESSAGE_LENGTH);
41
				try {
42
					_socket.receive(data);
43
44
					/* Is this a valid message type */
45
					Message incommingMessage = new Message();
46
					incommingMessage.readFromBuffer(data.getData(), data.getLength());
47
48
					/* Send an acknowledgement to the message originator */
49
					if (incommingMessage.getType() != RA_ACKNOWLEDGEMENT_MESSAGE) {
50
						byte[] responseBuffer = new byte[16];
51
						AcknowledgementMessage ack = new AcknowledgementMessage();
52
						ack.setTicket(incommingMessage.getTicket());
53
						ack.writeToBuffer(responseBuffer, 0);
54
						DatagramPacket response = new DatagramPacket(responseBuffer, 12, data.getAddress(), data.getPort());
55
						_socket.send(response);
56
					}
57
					processMessage(data.getData(), data.getLength(), data.getAddress());
58
				} catch (IOException e) {
59
					/* TO_DO: Must provide proper handler */
60
				}
61
			}
62
		}
63
64
		protected void processMessage(byte[] buffer, int bufferSize, InetAddress server) {
65
			long type = Message.readRALongFromBuffer(buffer, 8);
66
			switch ((int) type) {
67
			case RA_ACKNOWLEDGEMENT_MESSAGE:
68
				processAcknowledgementMessage(buffer, bufferSize, server);
69
				break;
70
			case RA_CONTROL_MESSAGE:
71
				processControlMessage(buffer, bufferSize, server);
72
				break;
73
			default:
74
				break;
75
			}
76
		}
77
78
		protected void processAcknowledgementMessage(byte[] buffer, int bufferSize, InetAddress server) {
79
			if (_ackHandler != null) {
80
				AcknowledgementMessage msg = new AcknowledgementMessage();
81
				msg.readFromBuffer(buffer, bufferSize);
82
				_ackHandler.incommingAcknowledgement(server, msg.getTicket());
83
			}
84
		}
85
86
		protected void processControlMessage(byte[] buffer, int bufferSize, InetAddress server) {
87
			if (_cmdHandler != null) {
88
				ControlMessage msg = new ControlMessage();
89
				msg.readFromBuffer(buffer, bufferSize);
90
91
				/* Valid pass on each command */
92
				int count = msg.getCommandCount();
93
				for (int i = 0; i < count; i++) {
94
					_cmdHandler.incommingCommand(server, msg.getCommand(i));
95
				}
96
			}
97
		}
98
	} // end class ControlDatagramServer
99
100
	/**
101
	 * ControlServer constructor comment.
102
	 */
103
	public ControlServerDaemon() {
104
		super();
105
	}
106
107
	public void sendMessage(byte[] buffer, int length, InetAddress addr) throws IOException {
108
		DatagramPacket message = new DatagramPacket(buffer, length, addr, CTL_PORT_NUM_SERVER);
109
		_sock.send(message);
110
	}
111
112
	/**
113
	 * Insert the method's description here. Creation date: (6/8/00 3:16:00 PM)
114
	 * 
115
	 * @param handler
116
	 *            com.ibm.jvmpi.client.AcknowledgementHandler
117
	 */
118
	public void setAcknowledgementHandler(AcknowledgementHandler handler) {
119
		_ackHandler = handler;
120
	}
121
122
	/**
123
	 * Insert the method's description here. Creation date: (6/8/00 3:15:10 PM)
124
	 * 
125
	 * @param handler
126
	 *            com.ibm.jvmpi.client.CommandHandler
127
	 */
128
	public void setCommandHandler(CommandHandler handler) {
129
		_cmdHandler = handler;
130
	}
131
132
	public void startServer() throws SocketException {
133
		/* Is the server already started? */
134
		if (_server != null)
135
			return;
136
		_sock = new DatagramSocket();
137
		_server = new DatagramServer();
138
		_server.setSocket(_sock);
139
		/* Don't block exit of the VM */
140
		_server.setDaemon(true);
141
		_server.start();
142
	}
143
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ConnectionFactory.java (+32 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ConnectionFactory.java,v 1.3 2005/10/05 17:33:53 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class ConnectionFactory {
16
17
	public static Connection getLocalConnection(Node node) {
18
		LocalConnectionImpl local = new LocalConnectionImpl();
19
		local.setNode(node);
20
21
		return local;
22
	}
23
24
	public static Connection getConnection(Node node) {
25
		return new ConnectionImpl();
26
	}
27
28
	public static Connection getSecuredConnection(Node node) {
29
		return new SecureConnectionImpl();
30
	}
31
32
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/Message.java (+268 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Message.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
import java.net.UnknownHostException;
17
18
public class Message implements Constants {
19
20
	/* The protocol version number */
21
	protected long _version = RA_VERSION;
22
23
	/* Length of the message */
24
	protected long _type = 0;
25
26
	/* The ticket number of the message */
27
	protected long _ticket = 0;
28
29
	/**
30
	 * Insert the method's description here. Creation date: (6/2/00 4:16:27 PM)
31
	 * 
32
	 * @return int
33
	 */
34
	public int getSize() {
35
		return 4 * sizeofLong;
36
	}
37
38
	/**
39
	 * Insert the method's description here. Creation date: (6/2/00 1:48:08 PM)
40
	 * 
41
	 * @return long
42
	 */
43
	public long getTicket() {
44
		return _ticket;
45
	}
46
47
	/**
48
	 * Insert the method's description here. Creation date: (11/1/00 3:22:45 PM)
49
	 * 
50
	 * @return long
51
	 */
52
	public long getType() {
53
		return _type;
54
	}
55
56
	/**
57
	 * Insert the method's description here. Creation date: (10/31/00 5:58:37 PM)
58
	 * 
59
	 * @return long
60
	 */
61
	public long getVersion() {
62
		return _version;
63
	}
64
65
	/**
66
	 * Insert the method's description here. Creation date: (6/2/00 1:50:09 PM)
67
	 * 
68
	 * @param buffer
69
	 *            byte[]
70
	 * @param length
71
	 *            int
72
	 */
73
	public int readFromBuffer(byte[] buffer, int offset) {
74
75
		/* magic number */
76
		readRALongFromBuffer(buffer, offset);
77
		offset += 4;
78
79
		/* version */
80
		_version = readRALongFromBuffer(buffer, offset);
81
		offset += 4;
82
83
		/* type */
84
		_type = readRALongFromBuffer(buffer, offset);
85
		offset += 4;
86
87
		/* ticket */
88
		_ticket = readRALongFromBuffer(buffer, offset);
89
		offset += 4;
90
91
		return offset;
92
	}
93
94
	/**
95
	 * Insert the method's description here. Creation date: (10/31/00 6:02:05 PM)
96
	 * 
97
	 * @return int
98
	 * @param buffer
99
	 *            byte[]
100
	 * @param offset
101
	 *            int
102
	 */
103
	public static long readRALongFromBuffer(byte[] buffer, int offset) {
104
		return (long) (buffer[0 + offset] << 24 & 0xff000000) | (long) (buffer[1 + offset] << 16 & 0x00ff0000) | (long) (buffer[2 + offset] << 8 & 0x0000ff00) | (long) (buffer[3 + offset] & 0x000000ff);
105
	}
106
107
	/**
108
	 * Insert the method's description here. Creation date: (10/31/00 6:03:31 PM)
109
	 * 
110
	 * @return int
111
	 * @param buffer
112
	 *            byte[]
113
	 * @param offset
114
	 *            int
115
	 */
116
	public static int readRAStringFromBuffer(byte[] buffer, int offset, RAString rastring) {
117
		long length = Message.readRALongFromBuffer(buffer, offset);
118
		String data;
119
		try {
120
			data = new String(buffer, offset + 4, (int) length, "UTF-8");
121
		} catch (Throwable e) {
122
			data = new String(buffer, 0, offset + 4, (int) length);
123
		}
124
		rastring.setData(data);
125
126
		return offset + rastring.getSize();
127
	}
128
129
	public static int readRABinaryArrayFromBuffer(byte[] buffer, int offset, RABinaryArray raarray) {
130
		long length = Message.readRALongFromBuffer(buffer, offset);
131
		raarray.setData(buffer, offset + 4, (int) length);
132
		return offset + raarray.getSize();
133
	}
134
135
	public static int readRAInetAddressFromBuffer(byte[] buffer, int offset, RAInetAddress ipaddr) {
136
		byte length = buffer[0 + offset];
137
		byte[] address = new byte[length];
138
		for (int i = 0; i < length; i++) {
139
			address[i] = buffer[1 + i];
140
		}
141
142
		ipaddr.setLength((int) length);
143
		ipaddr.setData(address);
144
145
		return offset + sizeofByte + length;
146
	}
147
148
	/**
149
	 * Insert the method's description here. Creation date: (6/2/00 1:48:28 PM)
150
	 * 
151
	 * @param ticket
152
	 *            java.lang.Long
153
	 */
154
	public void setTicket(long ticket) {
155
		_ticket = ticket;
156
	}
157
158
	/**
159
	 * Insert the method's description here. Creation date: (10/31/00 5:59:43 PM)
160
	 * 
161
	 * @param version
162
	 *            long
163
	 */
164
	public void setVersion(long version) {
165
		_version = version;
166
	}
167
168
	/**
169
	 * Insert the method's description here. Creation date: (10/31/00 6:02:05 PM)
170
	 * 
171
	 * @return int
172
	 * @param buffer
173
	 *            byte[]
174
	 * @param offset
175
	 *            int
176
	 */
177
	public static int writeRALongToBuffer(byte[] buffer, int offset, long ralong) {
178
		buffer[0 + offset] = (byte) (ralong >> 24 & 0x000000ff);
179
		buffer[1 + offset] = (byte) (ralong >> 16 & 0x000000ff);
180
		buffer[2 + offset] = (byte) (ralong >> 8 & 0x000000ff);
181
		buffer[3 + offset] = (byte) ralong;
182
		return offset + 4;
183
	}
184
185
	/**
186
	 * Insert the method's description here. Creation date: (10/31/00 6:03:31 PM)
187
	 * 
188
	 * @return int
189
	 * @param buffer
190
	 *            byte[]
191
	 * @param offset
192
	 *            int
193
	 */
194
	public static int writeRAStringToBuffer(byte[] buffer, int offset, RAString rastring) {
195
		byte[] strData;
196
		try {
197
			strData = rastring.getData().getBytes("UTF-8");
198
		} catch (Throwable e) {
199
			strData = rastring.getData().getBytes();
200
		}
201
		writeRALongToBuffer(buffer, offset, strData.length);
202
		System.arraycopy((Object) strData, 0, (Object) buffer, offset + 4, strData.length);
203
204
		return offset + rastring.getSize();
205
	}
206
207
	public static int writeRABinaryArrayToBuffer(byte[] buffer, int offset, RABinaryArray raarray) {
208
		if (raarray == null) {
209
			writeRALongToBuffer(buffer, offset, 0);
210
			return offset + sizeofLong;
211
		}
212
		byte[] data = raarray.getData();
213
		writeRALongToBuffer(buffer, offset, data.length);
214
		System.arraycopy(data, 0, buffer, offset + 4, data.length);
215
216
		return offset + raarray.getSize();
217
	}
218
219
	public static int writeRAInetAddressToBuffer(byte[] buffer, int offset, RAInetAddress addr) {
220
		if (addr == null) {
221
			buffer[offset] = 0;
222
			return offset + sizeofByte;
223
		}
224
		try {
225
			InetAddress address = addr.getAddress();
226
			if (address == null) {
227
				buffer[offset] = 0;
228
				return offset + sizeofByte;
229
			}
230
			byte[] bytes = address.getAddress();
231
			buffer[offset + 0] = (byte) bytes.length;
232
			for (int i = 0; i < bytes.length; i++) {
233
				buffer[offset + i + sizeofByte] = bytes[i];
234
			}
235
			return offset + sizeofByte + bytes.length;
236
237
		} catch (UnknownHostException e) {
238
			buffer[offset] = 0;
239
			return offset + sizeofByte;
240
241
		}
242
	}
243
244
	/**
245
	 * Insert the method's description here. Creation date: (6/2/00 1:49:08 PM)
246
	 * 
247
	 * @return int
248
	 * @param buffer
249
	 *            byte[]
250
	 */
251
	public int writeToBuffer(byte[] buffer, int offset) {
252
		int current = offset;
253
254
		/* Insert magic header */
255
		current = writeRALongToBuffer(buffer, current, RA_MAGIC);
256
257
		/* Insert the major and minor */
258
		current = writeRALongToBuffer(buffer, current, RA_VERSION);
259
260
		/* Insert the type */
261
		current = writeRALongToBuffer(buffer, current, _type);
262
263
		/* Insert the ticket */
264
		current = writeRALongToBuffer(buffer, current, _ticket);
265
266
		return current;
267
	}
268
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentRequestMonitorPortCommand.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentRequestMonitorPortCommand.java,v 1.1 2006/03/06 19:49:40 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class AgentRequestMonitorPortCommand extends MonitorPeerRequestPortCommand {
15
16
	public AgentRequestMonitorPortCommand() {
17
		super();
18
		_tag = RA_AGENT_REQUEST_MONITOR_PORT;
19
	}
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/SecureConnectionImpl.java (+251 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SecureConnectionImpl.java,v 1.9 2006/11/07 00:30:59 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.net.InetAddress;
17
import java.net.InetSocketAddress;
18
import java.net.Socket;
19
import java.net.SocketException;
20
import java.nio.channels.SocketChannel;
21
import java.security.KeyManagementException;
22
import java.security.NoSuchAlgorithmException;
23
24
import javax.net.ssl.KeyManager;
25
import javax.net.ssl.SSLContext;
26
import javax.net.ssl.SSLSession;
27
import javax.net.ssl.SSLSocket;
28
import javax.net.ssl.SSLSocketFactory;
29
import javax.net.ssl.TrustManager;
30
31
import junit.framework.Assert;
32
33
import org.eclipse.hyades.execution.security.ISecureClientParameters;
34
import org.eclipse.hyades.execution.core.file.socket.ISocketChannel;
35
import org.eclipse.hyades.execution.core.file.socket.ISocketChannelFactory;
36
import org.eclipse.hyades.execution.core.file.socket.SocketChannelFactory;
37
import org.eclipse.hyades.execution.security.LoginFailedException;
38
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
39
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
40
41
public class SecureConnectionImpl extends ConnectionImpl implements ISocketChannelFactory {
42
43
	public SecureConnectionImpl() {
44
		super();
45
	}
46
47
	public void connect(Node node, int port) throws IOException, LoginFailedException, SecureConnectionRequiredException, UntrustedAgentControllerException {
48
		int protocolOffset = 0;
49
50
		/* Set the node */
51
		_node = node;
52
53
		/* Determine our acceptable protocols */
54
		String[] sslProtocols = getSSLProtocols();
55
		SSLContext sslContext = null;
56
57
		/* Connect to the remote machine */
58
		boolean done = false;
59
60
		/* Get the SSL context */
61
		do {
62
			try {
63
				sslContext = getSSLContext(sslProtocols[protocolOffset]);
64
				done = true;
65
			} catch (NoSuchAlgorithmException e) {
66
				protocolOffset++;
67
			}
68
		} while (!done && (protocolOffset < sslProtocols.length));
69
70
		if (sslContext == null) {
71
			throw new IOException("Could not get SSL context. Protocols not supported.");
72
		}
73
74
		_socket = getSSLSocket(sslContext, port);
75
		_port = port;
76
77
		/* Set the cipher suites */
78
		String[] cipherSuites = getCipherSuites();
79
		((SSLSocket) _socket).setEnabledCipherSuites(cipherSuites);
80
		((SSLSocket) _socket).setUseClientMode(true);
81
82
		/*
83
		 * The underlying JSSE code returns the SSL socket before all the SSL handshakes, including client authentication, are completed. The handshake carries on, asynchronously, in the background. If the handshake fails then the socket is not usable. We synchronize things by calling getSession() on the SSL socket. The thread calling getSession() is forced to wait until the underlying SSL handshake is completed, and if the handshake fails then getSession() returns a null.
84
		 */
85
		SSLSession session = ((SSLSocket) _socket).getSession();
86
87
		/*
88
		 * If we could not establish a session we should throw an exception
89
		 */
90
		if (session == null) {
91
			throw new UntrustedAgentControllerException();
92
		}
93
		if (session.getCipherSuite().equals("SSL_NULL_WITH_NULL_NULL")) {
94
			throw new UntrustedAgentControllerException();
95
		}
96
97
		_node = node;
98
		this.init();
99
	}
100
101
	/**
102
	 * Creates a socket channel using the current _socket state as the abstracted element
103
	 * 
104
	 * @return
105
	 * @throws IOException
106
	 */
107
	private ISocketChannel create() throws IOException {
108
		Assert.assertNotNull(this._socket);
109
		return this.create(this._socket);
110
	}
111
112
	public ISocketChannel create(InetSocketAddress address) throws IOException {
113
114
		Assert.assertNotNull(address);
115
		Assert.assertNotNull(this._node);
116
117
		/*
118
		 * Creates a new socket channel to the given address/port combination, this new socket channel is a new connection and does not affect this secure connection implementation's connection status. It does attempt to use this secure connection implementation's credentials if possible to ease connection, as well as any of state that helps establish a new socket channel from this connection class.
119
		 * 
120
		 * The node must point to the same host, although the connection port can be different, The address host specified is ignored and only the port information is used in this case.
121
		 */
122
		SecureConnectionImpl connection = new SecureConnectionImpl() {
123
124
			public void init() {
125
126
				// Override to avoid base class socket reader thread
127
				try {
128
					this._socket.setSoTimeout(60000);
129
					this._socket.setTcpNoDelay(true);
130
					this._socket.setReuseAddress(true);
131
				} catch (SocketException e) {
132
					//
133
				}
134
135
			}
136
137
		};
138
139
		/*
140
		 * Create a new connection on a different port -- it is expected that no exceptions will occur due to already being validated on the same node as spawning secure connection impl
141
		 */
142
		try {
143
			connection.connect(this._node, address.getPort());
144
			return connection.create();
145
		} catch (SecureConnectionRequiredException e) {
146
			//
147
		} catch (UntrustedAgentControllerException e) {
148
			//
149
		} catch (IOException e) {
150
			//
151
		} catch (LoginFailedException e) {
152
			//
153
		}
154
		return null;
155
156
	}
157
158
	public ISocketChannel create(Socket socket) throws IOException {
159
		return SocketChannelFactory.getInstance().create(socket);
160
	}
161
162
	public ISocketChannel create(SocketChannel realChannel) {
163
		return SocketChannelFactory.getInstance().create(realChannel);
164
	}
165
166
	public ISocketChannel create(InetSocketAddress address, int timeout) throws IOException {
167
		// TODO Auto-generated method stub
168
		return null;
169
	}
170
171
	private String[] getCipherSuites() {
172
		Node node = getNode();
173
		String[] cipherSuites = null;
174
175
		ISecureClientParameters params = node.getSecurityParameters();
176
		if (params != null) {
177
			cipherSuites = params.getEnabledCipherSuites();
178
		}
179
		if (cipherSuites == null) {
180
			cipherSuites = ((SSLSocket) _socket).getSupportedCipherSuites();
181
		}
182
183
		return cipherSuites;
184
	}
185
186
	private SSLContext getSSLContext(String protocol) throws NoSuchAlgorithmException {
187
		Node node = getNode();
188
189
		KeyManager[] kms;
190
		TrustManager[] tms;
191
192
		/* Attach using SSL and initiate a handshake */
193
		SSLContext sslContext;
194
		sslContext = SSLContext.getInstance(protocol);
195
196
		kms = node.getSecurityParameters().getKeystoreManager().getKeyManagers();
197
		tms = node.getSecurityParameters().getKeystoreManager().getTrustManagers();
198
199
		try {
200
			sslContext.init(kms, tms, null);
201
		} catch (KeyManagementException e) {
202
			e.printStackTrace();
203
			return null;
204
		}
205
206
		return sslContext;
207
	}
208
209
	private String[] getSSLProtocols() {
210
		Node node = getNode();
211
212
		/* Determine our acceptable protocols */
213
		String[] sslProtocols;
214
		ISecureClientParameters param = node.getSecurityParameters();
215
		if (param != null) {
216
			sslProtocols = param.getEnabledProtocols();
217
			if (sslProtocols == null) {
218
				sslProtocols = new String[] { "SSL" };
219
			}
220
		} else {
221
			sslProtocols = new String[] { "SSL" };
222
		}
223
224
		return sslProtocols;
225
	}
226
227
	private SSLSocket getSSLSocket(SSLContext sslContext, int port) {
228
		int offset = 0;
229
		Node node = getNode();
230
		InetAddress[] addrs = node.getAllInetAddresses();
231
		SSLSocket sslSocket = null;
232
		boolean done = false;
233
234
		do {
235
			try {
236
				if (sslContext == null) {
237
					sslSocket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(addrs[offset], port);
238
					sslSocket.startHandshake();
239
					done = true;
240
				} else {
241
					sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(addrs[offset], port);
242
					done = true;
243
				}
244
			} catch (IOException e) {
245
				e.printStackTrace();
246
			}
247
		} while (!done && (offset < addrs.length));
248
249
		return sslSocket;
250
	}
251
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/Constants.java (+130 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Constants.java,v 1.9 2006/05/03 19:36:54 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public interface Constants {
16
	public static int DEFAULT_TIMEOUT = 10000;
17
18
	public static final String RA_MASTER_ADDRESS = "ramaster";
19
	public static final String RA_PIPE_NAMESPACE = "IBMRAC";
20
	public static final String RA_PIPE_NAMESPACE_WIN32 = "IBMAC";
21
22
	/* Various Message types currently available */
23
	public static final byte RA_ACKNOWLEDGEMENT_MESSAGE = 0x00000000;
24
	public static final byte RA_CONTROL_MESSAGE = 0x00000001;
25
26
	public final static long RA_MAGIC = 0x82656780;
27
	public final static byte RA_MAGIC_0 = (byte) (RA_MAGIC >> 24 & 0xff);
28
	public final static byte RA_MAGIC_1 = (byte) (RA_MAGIC >> 16 & 0xff);
29
	public final static byte RA_MAGIC_2 = (byte) (RA_MAGIC >> 8 & 0xff);
30
	public final static byte RA_MAGIC_3 = (byte) (RA_MAGIC & 0xff);
31
32
	public final static long RA_VERSION = 0x00000100;
33
34
	public final static long RA_AUTHENTICATE = 0x00000001;
35
	public final static long RA_AUTHENTICATION_FAILED = 0x00000002;
36
	public final static long RA_AUTHENTICATION_SUCCESSFUL = 0x00000003;
37
	public final static long RA_SERVER_SECURITY_REQUIREMENTS = 0x00000004;
38
	public final static long RA_LAUNCH_PROCESS = 0x00000010;
39
	public final static long RA_QUERY_PROCESS_LIST = 0x00000011;
40
	public final static long RA_QUERY_AGENT_LIST = 0x00000012;
41
	public final static long RA_REGISTER_AGENT_NOTIFICATION = 0x00000013;
42
	public final static long RA_ATTACH_TO_AGENT = 0x00000014;
43
	public final static long RA_DETACH_FROM_AGENT = 0x00000015;
44
	public final static long RA_START_MONITORING_AGENT_REMOTE = 0x00000016;
45
	public final static long RA_START_MONITORING_AGENT_LOCAL = 0x00000017;
46
	public final static long RA_STOP_MONITORING_AGENT = 0x00000018;
47
	public final static long RA_SET_NAME_VALUE_PAIR = 0x00000019;
48
	public final static long RA_CUSTOM_COMMAND = 0x0000001A;
49
	public final static long RA_KILL_PROCESS = 0x0000001B;
50
	public final static long RA_QUERY_AGENT_DETAILS = 0x0000001C;
51
	public final static long RA_BINARY_CUSTOM_COMMAND = 0x0000001D;
52
	public final static long RA_GET_PROPERTY_LIST = 0x0000001E;
53
	public final static long RA_MANAGE_FILE = 0x0000001F;
54
	public final static long RA_PROCESS_LAUNCHED = 0x00000020;
55
	public final static long RA_PROCESS_LIST = 0x00000021;
56
	public final static long RA_AGENT_LIST = 0x00000022;
57
	public final static long RA_AGENT_ACTIVE = 0x00000023;
58
	public final static long RA_AGENT_INACTIVE = 0x00000024;
59
	public final static long RA_ERROR_STRING = 0x00000025;
60
	public final static long RA_ATTACH_SUCCESSFUL = 0x00000026; // Not used
61
	public final static long RA_ATTACH_FAILED = 0x00000027; // Not used
62
	public final static long RA_AGENT_DETAILS = 0x00000028;
63
	public final static long RA_PROCESS_EXITED = 0x00000029;
64
	public final static long RA_PROPERTY_LIST = 0x0000002A;
65
	public final static long RA_AGENT_QUERY_STATE = 0x0000002B;
66
	public final static long RA_AGENT_ATTACHED = 0x0000002C;
67
	public final static long RA_AGENT_DETACHED = 0x0000002D;
68
	public final static long RA_LOCAL_AGENT_ACTIVE = 0x00000030; // Not used
69
	public final static long RA_AGENT_SCOPING_INFORMATION = 0x00000031;
70
	public final static long RA_AGENT_CONFIGURATION = 0x00000032;
71
	public final static long RA_AGENT_CONTROLLER_AVAILABLE = 0x00000050; // Not
72
																			// used
73
	public final static long RA_AGENT_CONTROLLER_UNAVAILABLE = 0x00000051; // Not
74
																			// used
75
	public final static long RA_AGENT_REQUEST_MONITOR = 0x00000061;
76
	public final static long RA_CONTROLLER_REQUEST_MONITOR = 0x00000062;
77
	public final static long RA_PEER_UNREACHABLE = 0x00000063;
78
	public final static long RA_CONTROLLER_MONITOR_PEER = 0x00000064; // Not
79
																		// used
80
	public final static long RA_AGENT_REQUEST_MONITOR_PORT = 0x00000065;
81
	public final static long RA_CONTROLLER_REQUEST_MONITOR_PORT = 0x00000066;
82
	public final static long RA_RESOURCE_LOCATION = 0x00000070;
83
	public final static long RA_CONSOLE_INFO = 0x00000080;
84
	public final static long RA_SHUTDOWN = 0x000000FF;
85
86
	public final static long RA_GET_FILE = 0x00000001;
87
	public final static long RA_PUT_FILE = 0x00000002;
88
	public final static long RA_DELETE_FILE = 0x00000003;
89
90
	/**
91
	 * Various constants that both the client and server must adhere to.
92
	 */
93
	public final static int CTL_PORT_NUM_SERVER = 10002; /*
94
															 * hardcoded to
95
															 * start with
96
															 */
97
	public final static int CTL_PORT_NUM_CLIENT = 10003; /*
98
															 * hardcoded to
99
															 * start with
100
															 */
101
	public final static int MESSAGE_HEADER_LENGTH = 10; /*
102
														 * 10 byte header to
103
														 * start with
104
														 */
105
	public final static int MAX_MESSAGE_LENGTH = 8096; /*
106
														 * The maximum size of a
107
														 * message
108
														 */
109
	public final static int MAX_COMMAND_LINE_LENGTH = 512; /*
110
															 * Maximum length of
111
															 * a command line
112
															 * string
113
															 */
114
	public final static int DATA_PORT_NUM_CLIENT = 10004;
115
	public final static int MAX_DATA_LENGTH = 4096; /*
116
													 * The size of the data
117
													 * buffer for sockets
118
													 */
119
120
	/*
121
	 * This package is ported from C, so to facilitate sizeof code for
122
	 * primitives the following constants are provided
123
	 */
124
125
	public final static int sizeofByte = 1;
126
	public static final int sizeofChar = 2;
127
	public static final int sizeofShort = 2;
128
	public static final int sizeofLong = 4;
129
130
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/QueryAgentListCommand.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: QueryAgentListCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class QueryAgentListCommand extends SimpleProcessCommand {
16
17
	/**
18
	 * QueryAgentList constructor comment.
19
	 */
20
	public QueryAgentListCommand() {
21
		super();
22
		_tag = RA_QUERY_AGENT_LIST;
23
	}
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ErrorCommand.java (+88 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ErrorCommand.java,v 1.3 2006/04/24 14:58:32 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class ErrorCommand extends SimpleAgentInfoCommand implements Constants {
16
17
	protected long _severity;
18
19
	protected RAString _errorId = new RAString("");
20
21
	protected RAString _errorString = new RAString("");
22
23
	/**
24
	 * ErrorCommand constructor comment.
25
	 */
26
	public ErrorCommand() {
27
		super();
28
		_tag = RA_ERROR_STRING;
29
	}
30
31
	public String getErrorId() {
32
		return _errorId._data;
33
	}
34
35
	public String getErrorString() {
36
		return _errorString._data;
37
	}
38
39
	public long getSeverity() {
40
		return _severity;
41
	}
42
43
	/**
44
	 * getSize method comment.
45
	 */
46
	public int getSize() {
47
		int size = super.getSize();
48
		size += sizeofLong;
49
		size += _errorId.getSize();
50
		size += _errorString.getSize();
51
		return size;
52
	}
53
54
	/**
55
	 * readFromBuffer method comment.
56
	 */
57
	public int readFromBuffer(byte[] buffer, int offset) {
58
		int current = super.readFromBuffer(buffer, offset);
59
		_severity = Message.readRALongFromBuffer(buffer, current);
60
		current += sizeofLong;
61
		current = Message.readRAStringFromBuffer(buffer, current, _errorId);
62
		current = Message.readRAStringFromBuffer(buffer, current, _errorString);
63
		return current;
64
	}
65
66
	public void setErrorId(String id) {
67
		_errorId = new RAString(id);
68
	}
69
70
	public void setErrorString(String s) {
71
		_errorString = new RAString(s);
72
	}
73
74
	public void setSeverity(long sev) {
75
		_severity = sev;
76
	}
77
78
	/**
79
	 * writeToBuffer method comment.
80
	 */
81
	public int writeToBuffer(byte[] buffer, int offset) {
82
		int current = super.writeToBuffer(buffer, offset);
83
		current = Message.writeRALongToBuffer(buffer, current, _severity);
84
		current = Message.writeRAStringToBuffer(buffer, current, _errorId);
85
		current = Message.writeRAStringToBuffer(buffer, current, _errorString);
86
		return current;
87
	}
88
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ErrorListener.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ErrorListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
/**
16
 * This is the interface that all errors will notified on.
17
 */
18
public interface ErrorListener {
19
20
	void error(String errorId, String error);
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/MultiplexedDataServer.java (+173 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: MultiplexedDataServer.java,v 1.10 2006/10/30 18:25:49 jptoomey Exp $
8
 *
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 ***********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
17
import org.eclipse.hyades.execution.local.control.Agent;
18
import org.eclipse.hyades.execution.local.control.AgentListener;
19
import org.eclipse.hyades.execution.local.control.InactiveProcessException;
20
import org.eclipse.hyades.execution.local.control.ProcessImpl;
21
22
/**
23
 * Please see TCPDataServer for implmentation details.
24
 */
25
public class MultiplexedDataServer implements AgentListener, Constants {
26
	private Agent _agent;
27
	private DataProcessor _processor;
28
	private long magicNumber = 0xFEEDC0DE;
29
	private long terminationCode = 0xDEADC0DE;
30
	private InetAddress inetaddr = null;
31
32
	/* Different types of data */
33
	public static final byte BINARY_DATA = 0;
34
	public static final byte UTF8_STRING_DATA = 1;
35
	public static final byte UNICODE_STRING_DATA = 2;
36
37
	public void startServer(DataProcessor processor) throws Exception {
38
		_processor = processor;
39
	}
40
41
	public boolean isProcessing() {
42
		return true; // always processing
43
	}
44
45
	public void stopServer() {
46
	}
47
48
	public void resumeServer() {
49
	}
50
51
	public void resumeServer(DataProcessor processor) {
52
	}
53
54
	public void shutdownServer() {
55
		this._processor = null;
56
	}
57
58
	public void incommingData(byte[] b, InetAddress peer) {
59
		_processor.incommingData(b, b.length, peer);
60
	}
61
62
	public void incommingData(char[] c, InetAddress peer) {
63
		_processor.incommingData(c, c.length, peer);
64
	}
65
66
	public void agentActive(Agent agent) {
67
		try {
68
			inetaddr = agent.getProcess().getNode().getInetAddress();
69
		} catch (InactiveProcessException e) {
70
		}
71
	}
72
73
	public void agentInactive(Agent agent) {
74
		this._agent = agent;
75
	}
76
77
	public void error(Agent agent, String errorId, String errorMessage) {
78
	}
79
80
	public void handleCommand(Agent agent, CommandElement command) {
81
		switch ((int) command.getTag()) {
82
		case (int) Constants.RA_BINARY_CUSTOM_COMMAND:
83
			BinaryCustomCommand binaryCustomCommand = (BinaryCustomCommand) command;
84
			int binaryDataLength;
85
			byte[] binaryData;
86
87
			// The byte array data and length
88
			binaryData = binaryCustomCommand.getDataBinary();
89
			binaryDataLength = binaryData.length;
90
91
			if (binaryDataLength >= sizeofLong) {
92
				// Read the magic number
93
				long code = Message.readRALongFromBuffer(binaryData, 0);
94
95
				if (code == magicNumber) {
96
					// Read the actual multiplexed data
97
					byte b[] = new byte[binaryDataLength - 4];
98
					System.arraycopy(binaryData, 4, b, 0, binaryDataLength - 4);
99
					processData(b, inetaddr);
100
				} else if (code == terminationCode) {
101
					/* Notify that the flusher is exiting */
102
					if (_processor instanceof DataServerListener) {
103
						((DataServerListener) _processor).dataServerExited();
104
					}
105
					if (this._agent != null && this._agent.getProcess() != null && this._agent.getProcess() instanceof ProcessImpl) {
106
						((ProcessImpl) this._agent.getProcess()).removeAgent(this._agent);
107
					}
108
				}
109
			}
110
			break;
111
		}
112
	}
113
114
	private void processData(byte[] data, InetAddress addr) {
115
		if (data.length > Constants.MESSAGE_HEADER_LENGTH) {
116
			if (isValidHeader(data)) {
117
				int length = (int) getMessageLength(data);
118
				byte type = getMessageType(data);
119
120
				if (length + Constants.MESSAGE_HEADER_LENGTH <= data.length) {
121
					if (type == BINARY_DATA || type == UTF8_STRING_DATA) {
122
						byte[] forwardBuffer = new byte[length];
123
						System.arraycopy(data, Constants.MESSAGE_HEADER_LENGTH, forwardBuffer, 0, length);
124
						_processor.incommingData(forwardBuffer, length, addr);
125
					} else if (type == UNICODE_STRING_DATA) { // double-byte
126
						int strlen = length / 2;
127
						char[] forwardBuffer = new char[strlen];
128
						for (int i = 0; i < strlen; i++) {
129
							forwardBuffer[i] = (char) ((char) data[Constants.MESSAGE_HEADER_LENGTH + 2 * i] | (char) (data[Constants.MESSAGE_HEADER_LENGTH + 2 * i + 1] << 8));
130
						}
131
						_processor.incommingData(forwardBuffer, strlen, addr);
132
					} else {
133
						System.err.println("ERROR: Corrupted data in multiplexed data");
134
					}
135
				} else {
136
					System.err.println("ERROR: multiplexed message does not have enough bytes as specified in the message length attribute");
137
				}
138
			} else {
139
				System.err.println("ERROR: multiplexed message does not have a valid header");
140
			}
141
		} else {
142
			System.err.println("ERROR: multiplexed message does not have enough header bytes");
143
		}
144
	}
145
146
	/**
147
	 * Get the length of the current message
148
	 */
149
	private long getMessageLength(byte[] b) {
150
		return Message.readRALongFromBuffer(b, 5);
151
	}
152
153
	/**
154
	 * Get the message type. There are currently three types of messages. BINARY_DATA, UTF8_STRING_DATA, UNICODE_STRING_DATA.
155
	 */
156
	private byte getMessageType(byte[] b) {
157
		return b[9];
158
159
	}
160
161
	/**
162
	 * Check the message magic number. If the magic number is incorrect we need to go into recovery mode
163
	 */
164
	private boolean isValidHeader(byte[] b) {
165
		boolean valid = false;
166
167
		if ((b[0] == Constants.RA_MAGIC_0) && (b[1] == Constants.RA_MAGIC_1) && (b[2] == Constants.RA_MAGIC_2) && (b[3] == Constants.RA_MAGIC_3)) {
168
			valid = true;
169
		}
170
171
		return valid;
172
	}
173
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/CommandHandler.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CommandHandler.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import org.eclipse.hyades.execution.local.common.CommandElement;
16
17
public interface CommandHandler {
18
19
	void incommingCommand(Node node, CommandElement command);
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/SimpleAgentInfoCommand.java (+85 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SimpleAgentInfoCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public abstract class SimpleAgentInfoCommand extends SimpleProcessCommand implements Constants {
16
17
	protected RAString _agentName = new RAString("");
18
19
	/**
20
	 * ProcessInfoCommandEntry constructor comment.
21
	 */
22
	public SimpleAgentInfoCommand() {
23
		super();
24
	}
25
26
	/**
27
	 * Insert the method's description here. Creation date: (9/11/00 9:12:04 PM)
28
	 * 
29
	 * @return java.lang.String
30
	 */
31
	public String getAgentName() {
32
		if (_agentName != null)
33
			return _agentName.getData();
34
		return null;
35
	}
36
37
	/**
38
	 * Insert the method's description here. Creation date: (6/8/00 12:54:50 PM)
39
	 * 
40
	 * @return int
41
	 */
42
	public int getSize() {
43
		return super.getSize() + _agentName.getSize();
44
	}
45
46
	/**
47
	 * Insert the method's description here. Creation date: (9/11/00 9:25:14 PM)
48
	 * 
49
	 * @return int
50
	 * @param buffer
51
	 *            byte[]
52
	 * @param length
53
	 *            int[]
54
	 */
55
	public int readFromBuffer(byte[] buffer, int offset) {
56
		int current = super.readFromBuffer(buffer, offset);
57
		current = Message.readRAStringFromBuffer(buffer, current, _agentName);
58
		return current;
59
	}
60
61
	/**
62
	 * Insert the method's description here. Creation date: (9/11/00 9:11:41 PM)
63
	 * 
64
	 * @param name
65
	 *            java.lang.String
66
	 */
67
	public void setAgentName(String name) {
68
		_agentName = new RAString(name);
69
	}
70
71
	/**
72
	 * Insert the method's description here. Creation date: (7/21/00 2:35:32 PM)
73
	 * 
74
	 * @return int
75
	 * @param buffer
76
	 *            byte[]
77
	 * @param offset
78
	 *            int
79
	 */
80
	public int writeToBuffer(byte[] buffer, int offset) {
81
		int current = super.writeToBuffer(buffer, offset);
82
		current = Message.writeRAStringToBuffer(buffer, current, _agentName);
83
		return current;
84
	}
85
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentScopingInformationCommand.java (+151 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentScopingInformationCommand.java,v 1.3 2006/03/06 19:49:40 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentScopingInformationCommand extends CommandElement implements Constants {
16
	private long processId;
17
	private long messageProcessId;
18
	private RAString processUUID = new RAString();
19
	private RAString agentName = new RAString();
20
	private RAString agentUUID = new RAString();
21
	private RAString agentType = new RAString();
22
	private RAString nodeUUID = new RAString();
23
24
	public AgentScopingInformationCommand() {
25
		_tag = Constants.RA_AGENT_SCOPING_INFORMATION;
26
	}
27
28
	public int getSize() {
29
		int size = 0;
30
31
		size += super.getSize();
32
33
		size += sizeofLong; // processId
34
		if (System.getProperty("os.name").startsWith("Linux")) {
35
			size += sizeofLong; // messageProcessId;
36
		}
37
		size += processUUID.getSize();
38
		size += agentName.getSize();
39
		size += agentUUID.getSize();
40
		size += agentType.getSize();
41
		size += nodeUUID.getSize();
42
43
		return size;
44
	}
45
46
	/**
47
	 * Read the buffer to populate the class content. No need to read the tag
48
	 * since it is already being read by the handler
49
	 */
50
	public int readFromBuffer(byte[] buffer, int offset) {
51
		int current = offset;
52
53
		current = super.readFromBuffer(buffer, current);
54
55
		processId = Message.readRALongFromBuffer(buffer, current);
56
		current += sizeofLong;
57
58
		if (System.getProperty("os.name").startsWith("Linux")) {
59
			messageProcessId = Message.readRALongFromBuffer(buffer, current);
60
			current += sizeofLong;
61
		}
62
63
		current = Message.readRAStringFromBuffer(buffer, current, processUUID);
64
		current = Message.readRAStringFromBuffer(buffer, current, agentName);
65
		current = Message.readRAStringFromBuffer(buffer, current, agentUUID);
66
		current = Message.readRAStringFromBuffer(buffer, current, agentType);
67
		current = Message.readRAStringFromBuffer(buffer, current, nodeUUID);
68
69
		return current;
70
	}
71
72
	/**
73
	 * Need to write the class content to the buffer, that includes the tag as
74
	 * well
75
	 */
76
	public int writeToBuffer(byte[] buffer, int offset) {
77
		int current = offset;
78
79
		current = super.writeToBuffer(buffer, current);
80
		current = Message.writeRALongToBuffer(buffer, current, processId);
81
82
		if (System.getProperty("os.name").startsWith("Linux")) {
83
			current = Message.writeRALongToBuffer(buffer, current, messageProcessId);
84
		}
85
86
		current = Message.writeRAStringToBuffer(buffer, current, processUUID);
87
		current = Message.writeRAStringToBuffer(buffer, current, agentName);
88
		current = Message.writeRAStringToBuffer(buffer, current, agentUUID);
89
		current = Message.writeRAStringToBuffer(buffer, current, agentType);
90
		current = Message.writeRAStringToBuffer(buffer, current, nodeUUID);
91
92
		return current;
93
	}
94
95
	public RAString getAgentName() {
96
		return agentName;
97
	}
98
99
	public void setAgentName(RAString agentName) {
100
		this.agentName = agentName;
101
	}
102
103
	public RAString getAgentType() {
104
		return agentType;
105
	}
106
107
	public void setAgentType(RAString agentType) {
108
		this.agentType = agentType;
109
	}
110
111
	public RAString getAgentUUID() {
112
		return agentUUID;
113
	}
114
115
	public void setAgentUUID(RAString agentUUID) {
116
		this.agentUUID = agentUUID;
117
	}
118
119
	public long getMessageProcessId() {
120
		return messageProcessId;
121
	}
122
123
	public void setMessageProcessId(long messageProcessId) {
124
		this.messageProcessId = messageProcessId;
125
	}
126
127
	public RAString getNodeUUID() {
128
		return nodeUUID;
129
	}
130
131
	public void setNodeUUID(RAString nodeUUID) {
132
		this.nodeUUID = nodeUUID;
133
	}
134
135
	public long getProcessId() {
136
		return processId;
137
	}
138
139
	public void setProcessId(long processId) {
140
		this.processId = processId;
141
	}
142
143
	public RAString getProcessUUID() {
144
		return processUUID;
145
	}
146
147
	public void setProcessUUID(RAString processUUID) {
148
		this.processUUID = processUUID;
149
	}
150
151
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/InvalidMessageException.java (+38 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: InvalidMessageException.java,v 1.4 2005/10/08 14:28:53 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class InvalidMessageException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = -4943674624497132355L;
21
22
	/**
23
	 * InvalidMessageException constructor comment.
24
	 */
25
	public InvalidMessageException() {
26
		super();
27
	}
28
29
	/**
30
	 * InvalidMessageException constructor comment.
31
	 * 
32
	 * @param s
33
	 *            java.lang.String
34
	 */
35
	public InvalidMessageException(String s) {
36
		super(s);
37
	}
38
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/KillProcessCommand.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: KillProcessCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class KillProcessCommand extends SimpleProcessCommand {
16
17
	/**
18
	 * KillProcessCommand constructor comment.
19
	 */
20
	public KillProcessCommand() {
21
		super();
22
		_tag = RA_KILL_PROCESS;
23
	}
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/CommandHandler.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CommandHandler.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
17
public interface CommandHandler {
18
19
	void incommingCommand(InetAddress server, CommandElement command);
20
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/TCPDataServer.java (+1137 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: TCPDataServer.java,v 1.36 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InterruptedIOException;
18
import java.net.InetAddress;
19
20
import javax.xml.parsers.SAXParser;
21
import javax.xml.parsers.SAXParserFactory;
22
23
import org.eclipse.hyades.execution.local.CommunicationDebug;
24
import org.eclipse.tptp.platform.agentcontroller.internal.DataConnection;
25
26
public class TCPDataServer {
27
	private String MESSAGE_VALUE_ID = "messageValue";
28
29
	private DataConnection _dataConnection = null;
30
31
	private TCPDataProcessor _server = null;
32
33
	private BufferFlusher _flusher = null;
34
35
	private int _port;
36
37
	private boolean _isDataServerRunning = true; // Bug 90153
38
39
	/*
40
	 * Buffers for getting incomming data off the socket reader and onto a dispatch thread
41
	 */
42
	private static final short NUM_BUFFERS = 32;
43
44
	private SingleBuffer[] _bufferArray;
45
46
	private short _currentFullBuffers = 0;
47
48
	/* Different types of data */
49
	public static final byte BINARY_DATA = 0;
50
51
	public static final byte UTF8_STRING_DATA = 1;
52
53
	public static final byte UNICODE_STRING_DATA = 2;
54
55
	private int totalBytes = 0; // Bug 90153
56
57
	public static final int BUFFER_SIZE = 8 * Constants.MAX_MESSAGE_LENGTH; // 64K
58
59
	public TCPDataServer() {
60
		super();
61
	}
62
63
	public TCPDataServer(DataConnection connection) {
64
		_dataConnection = connection;
65
	}
66
67
	class SingleBuffer implements Constants {
68
		public InetAddress addr;
69
70
		public int length = 0;
71
72
		public int size = MAX_MESSAGE_LENGTH;
73
74
		public byte[] data = new byte[MAX_MESSAGE_LENGTH];
75
76
	}
77
78
	class TCPDataProcessor extends Thread implements Constants {
79
		boolean _processing = true;
80
		protected boolean _shutdown = false; /* 9707 */
81
		protected short _currentFillerBuffer = 0;
82
83
		public TCPDataProcessor() {
84
		}
85
86
		/* 9707 */
87
		public void resumeProcessing() {
88
			synchronized (this) {
89
				_processing = true;
90
			}
91
		}
92
93
		/* 9707 */
94
		public void pauseProcessing() {
95
			synchronized (this) {
96
				_processing = false;
97
			}
98
		}
99
100
		/* 9707 */
101
		public boolean isProcessing() {
102
			synchronized (this) {
103
				if (CommunicationDebug.INSTANCE.debug) {
104
					System.out.println("TCPDataServer.isProcessing()=" + _processing + " - " + this);
105
				}
106
				return _processing;
107
			}
108
		}
109
110
		/* 9707 */
111
		public void shutdown() {
112
			if (CommunicationDebug.INSTANCE.debug) {
113
				System.out.println("TCPDataServer.shutdown() - " + this);
114
			}
115
			_shutdown = true;
116
			pauseProcessing();
117
			interrupt();
118
			if (CommunicationDebug.INSTANCE.debug) {
119
				System.out.println("TCPDataServer.shutdown(): after - " + this);
120
			}
121
		}
122
123
		public void run() {
124
			_isDataServerRunning = true; // Bug 90153
125
126
			/* Run forever */
127
			outer: while (!_shutdown || (_currentFullBuffers != 0)) { /* 9707 */
128
				if (isProcessing()) {
129
					_dataConnection.create();
130
					InputStream is;
131
					do {
132
						is = _dataConnection.getInputStream();
133
						if (is == null) {
134
							try {
135
								Thread.sleep(1000);
136
							} catch (InterruptedException e) {
137
								e.printStackTrace();
138
							}
139
						}
140
					} while (is == null);
141
142
					while (true) {
143
						/* If all the buffers are full wait for the first one to be emptied */
144
						while (_currentFullBuffers == NUM_BUFFERS) {
145
							synchronized (_bufferArray[0]) {
146
								try {
147
									_bufferArray[0].wait();
148
								} catch (InterruptedException e) {
149
								}
150
							}
151
						}
152
153
						/* Fill the next buffer */
154
						_bufferArray[_currentFillerBuffer].addr = _dataConnection.getAddress();
155
						try {
156
							_bufferArray[_currentFillerBuffer].length = is.read(_bufferArray[_currentFillerBuffer].data);
157
							/* System.out.println("---Read "+_bufferArray[_currentFillerBuffer].length+" bytes"); */
158
							int _bytes = _bufferArray[_currentFillerBuffer].length; // Bug 90153
159
							totalBytes += _bytes;
160
							// System.out.println("---------------------Read "+_bytes+" into _bufferArray["+_currentFillerBuffer+"]");
161
							// System.out.println("---------------------Read "+totalBytes+" bytes in total");
162
							if (_bytes == -1) {
163
								_isDataServerRunning = false;
164
							}
165
						} catch (InterruptedIOException e) {
166
							if (CommunicationDebug.INSTANCE.debug) {
167
								e.printStackTrace(System.out);
168
							}
169
							/* Read timeout, don't want to wait too long */
170
171
							/* This is used to terminate the thread if the process is killed abnormally */
172
							if (_shutdown && (_currentFullBuffers == 0)) {
173
								pauseProcessing();
174
								_isDataServerRunning = false; // Bug 90153
175
								_dataConnection.destroyConnection(); /* 9707 */
176
								break outer;
177
							}
178
						} catch (IOException e) {
179
							if (CommunicationDebug.INSTANCE.debug) {
180
								e.printStackTrace(System.out);
181
							}
182
							/* Socket is toast, we are done */
183
							pauseProcessing();
184
							_isDataServerRunning = false; // Bug 90153
185
							_dataConnection.destroyConnection(); /* 9707 */
186
							break outer;
187
						}
188
189
						/* Is the connection closed? */
190
						if (_bufferArray[_currentFillerBuffer].length < 0) {
191
							pauseProcessing();
192
							_isDataServerRunning = false; // Bug 90153
193
							/* Will hit here when detaching agent */
194
							_dataConnection.destroyConnection();
195
							break outer;
196
						}
197
						synchronized (_bufferArray[0]) {
198
							if (_bufferArray[_currentFillerBuffer].length > 0) {
199
								/* Move on to the next buffer */
200
								_currentFillerBuffer++;
201
								if (_currentFillerBuffer == NUM_BUFFERS) {
202
									_currentFillerBuffer = 0;
203
								}
204
								_currentFullBuffers++;
205
206
								/* Is this the first buffer filled? */
207
								if (_currentFullBuffers == 1) {
208
									_bufferArray[0].notifyAll();
209
								}
210
							}
211
						}
212
					}
213
				} else {
214
					try {
215
						if (CommunicationDebug.INSTANCE.debug) {
216
							System.out.println("TCPDataProcessor.run() - Monitoring is stopped, keep this thread in sleep state !");
217
						}
218
						/* Monitoring is stopped, keep this thread in sleep state */
219
						sleep(1000); /* 9707 */
220
					} catch (InterruptedException e) {
221
					}
222
				}
223
			}
224
		}
225
226
	} /* end class TCPDataProcessor */
227
228
	class BufferFlusher extends Thread implements Constants {
229
		private DataProcessor _processor = null;
230
231
		private byte[] _binaryForwardBuffer = new byte[MAX_MESSAGE_LENGTH];
232
233
		private char[] _stringForwardBuffer = new char[MAX_MESSAGE_LENGTH];
234
235
		private byte[] _messageHeader = new byte[MESSAGE_HEADER_LENGTH];
236
237
		private long _currentBufferSize = MAX_MESSAGE_LENGTH;
238
239
		private short _currentFlusherBuffer = 0;
240
241
		private int _currentHeaderOffset = 0;
242
243
		private int _bytesWritten = 0;
244
245
		public void setProcessor(DataProcessor processor) {
246
			_processor = processor;
247
		}
248
249
		/**
250
		 * Load the _messageHeader from a buffer of data
251
		 * 
252
		 * @param data -
253
		 *            the byte[] holding the raw data.
254
		 * @param offset -
255
		 *            where the header starts in the raw data buffer.
256
		 * @param length -
257
		 *            the length of the raw data buffer.
258
		 * @returns - the new offset in the raw data buffer to continue reading from.
259
		 */
260
		protected int loadMessageHeader(byte[] data, int offset, int limit) {
261
			/* Load all we can into the header */
262
			while (offset < limit && _currentHeaderOffset < MESSAGE_HEADER_LENGTH) {
263
				_messageHeader[_currentHeaderOffset++] = data[offset++];
264
			}
265
			return offset;
266
		}
267
268
		/**
269
		 * Get the length of the current message
270
		 */
271
		protected long getMessageLength() {
272
			return Message.readRALongFromBuffer(_messageHeader, 5);
273
		}
274
275
		/**
276
		 * Get the message type. There are currently three types of messages. BINARY_DATA, UTF8_STRING_DATA, UNICODE_STRING_DATA.
277
		 */
278
		protected byte getMessageType() {
279
			return _messageHeader[9];
280
281
		}
282
283
		/**
284
		 * Check the message magic number. If the magic number is incorrect we need to go into recovery mode
285
		 */
286
		protected boolean checkMessageMagic() {
287
			return true;
288
		}
289
290
		/**
291
		 * Recursively process a buffer of raw data.
292
		 */
293
		protected int processData(byte[] data, int offset, int limit, InetAddress addr) {
294
			long messageLength;
295
			byte type;
296
			int current;
297
298
			current = offset;
299
300
			/* Is there data to process */
301
			if (offset >= limit) {
302
				return limit;
303
			}
304
305
			/* Is this a new message? */
306
			if (_currentHeaderOffset < MESSAGE_HEADER_LENGTH) {
307
				/* Load the message header */
308
				current = this.loadMessageHeader(data, current, limit);
309
310
				/* Did we get the entire header, if not return */
311
				if (current == limit) {
312
					return current;
313
				}
314
315
				/* Resize and compress the forward buffer if nessesary */
316
				if (getMessageLength() >= _currentBufferSize) {
317
					type = getMessageType();
318
319
					if (type == BINARY_DATA || type == UTF8_STRING_DATA) {
320
						byte[] replacement = new byte[(int) getMessageLength()];
321
						/* Shift the available data to the front of the buffer */
322
						System.arraycopy(data, current, replacement, 0, (limit - current));
323
						_bytesWritten = limit - current;
324
						_binaryForwardBuffer = replacement;
325
					} else {
326
						char[] replacement = new char[(int) getMessageLength()];
327
						/* Shift the available data to the front of the buffer */
328
						for (int i = 0; i < limit - current + 1; i++) {
329
							try {
330
								replacement[i] = (char) data[i + current];
331
							} catch (Exception e) {
332
								System.out.println("BufferFlusher.processData(): replacement[i]=(char)data[i+current];");
333
								System.out.println("BufferFlusher.processData(): repalcement.length=" + replacement.length + ", data.length=" + data.length + ", i=" + i + ", current=" + current);
334
								e.printStackTrace(System.out);
335
								throw new RuntimeException(e);
336
							}
337
						}
338
						_bytesWritten = limit - current;
339
						_stringForwardBuffer = replacement;
340
					}
341
					return limit;
342
				}
343
			}
344
345
			/*
346
			 * Validate the message header, if we are in recovery mode try and look at the next offset
347
			 */
348
			if (!checkMessageMagic()) {
349
				System.out.println("BufferFlusher.processData(): Corrupt data");
350
				_currentHeaderOffset = 0;
351
				return processData(data, offset + 1, limit, addr);
352
353
			}
354
355
			/* How long is the current message */
356
			messageLength = getMessageLength();
357
358
			/* What is the message type */
359
			type = getMessageType();
360
361
			/* Process the entire buffer */
362
			while (current < limit) {
363
364
				if (type == BINARY_DATA || type == UTF8_STRING_DATA) {
365
					/* Copy as many bytes as possible into the forwarding buffer */
366
					while (current < limit && _bytesWritten < messageLength) {
367
						_binaryForwardBuffer[_bytesWritten++] = data[current++];
368
					}
369
					/* Are we at the end of the message? If so forward to the handler */
370
					if (_bytesWritten == messageLength) {
371
						_processor.incommingData(_binaryForwardBuffer, _bytesWritten, addr);
372
						_bytesWritten = 0;
373
						_currentHeaderOffset = 0;
374
						/* Continue processing this data buffer */
375
						current = this.processData(data, current, limit, addr);
376
					}
377
				} else if (type == UNICODE_STRING_DATA) {
378
					/* Copy as many bytes as possible into the forwarding buffer */
379
					while (offset < limit && _bytesWritten < messageLength) {
380
						_stringForwardBuffer[_bytesWritten >> 1] = (char) ((char) data[current++] | (char) (data[current++] << 8));
381
						_bytesWritten += 2;
382
					}
383
					/* Are we at the end of the message? If so forward to the handler */
384
					if (_bytesWritten == messageLength) {
385
						_processor.incommingData(_stringForwardBuffer, _bytesWritten, addr);
386
						_bytesWritten = 0;
387
						_currentHeaderOffset = 0;
388
						/* Continue processing this data buffer */
389
						current = this.processData(data, current, limit, addr);
390
					}
391
				} else {
392
					/* Invalid message type */
393
					/* Copy as many bytes as possible into the forwarding buffer */
394
					while (offset < limit && _bytesWritten < messageLength) {
395
						_binaryForwardBuffer[_bytesWritten++] = data[current++];
396
					}
397
					/* Are we at the end of the message? If so forward to the handler */
398
					if (_bytesWritten == messageLength) {
399
						_processor.incommingData(_binaryForwardBuffer, _bytesWritten, addr);
400
						_bytesWritten = 0;
401
						_currentHeaderOffset = 0;
402
						/* Continue processing this data buffer */
403
						current = this.processData(data, current, limit, addr);
404
					}
405
				}
406
			}
407
			return current;
408
		}
409
410
		public void run() {
411
			if (CommunicationDebug.INSTANCE.debugMessageValue) {
412
				MESSAGE_VALUE_ID = MESSAGE_VALUE_ID + "_" + this.hashCode();
413
			}
414
			// outer: while(isProcessing() || (_currentFullBuffers != 0) || _isFinished == false) { /* 237169 make sure buffer is empty before exiting */
415
			outer: while (isProcessing() || (_currentFullBuffers != 0)) { // Bug 90153
416
				/* If there are no current buffers to empty wait */
417
				if (_currentFullBuffers == 0) {
418
					_processor.waitingForData();
419
					do {
420
						synchronized (_bufferArray[0]) {
421
							try {
422
								_bufferArray[0].wait(1000);
423
							} catch (InterruptedException e) {
424
								return;
425
							}
426
						}
427
						if (!isProcessing() && _currentFullBuffers == 0) {
428
							break outer;
429
						}
430
					} while (_currentFullBuffers == 0);
431
				}
432
433
				/* Empty the current buffer */
434
				if (_bufferArray[_currentFlusherBuffer].length > 0) {
435
					// System.out.println("---- Flushing "+ _bufferArray[_currentFlusherBuffer].length+" bytes from _bufferArray["+_currentFlusherBuffer+"]");
436
					if (CommunicationDebug.INSTANCE.debugMessageValue) {
437
						CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID, _bufferArray[_currentFlusherBuffer].data, 0, _bufferArray[_currentFlusherBuffer].length);
438
					}
439
					processData(_bufferArray[_currentFlusherBuffer].data, 0, _bufferArray[_currentFlusherBuffer].length, _bufferArray[_currentFlusherBuffer].addr);
440
					/* Mark the buffer as empty */
441
					_bufferArray[_currentFlusherBuffer].length = 0;
442
443
				}
444
445
				synchronized (_bufferArray[0]) {
446
447
					_currentFullBuffers--;
448
449
					/* Increment the flusher to the next buffer */
450
					_currentFlusherBuffer++;
451
					if (_currentFlusherBuffer == NUM_BUFFERS) {
452
						_currentFlusherBuffer = 0;
453
					}
454
455
					/*
456
					 * If the buffers were half full before this flush notify the filler it can continue. Generally this could be NUMBUFFERS but not as efficient as more thread switches happen
457
					 */
458
					if (_currentFullBuffers == 0) {
459
						_bufferArray[0].notifyAll();
460
					}
461
				}
462
			}
463
464
			/* Notify that the flusher is exiting */
465
			// System.out.println("Notify that the flusher is exiting!!!");
466
			// System.out.println("isProcessing() = "+isProcessing()+", _currentFullBuffers = " +_currentFullBuffers);
467
			if (_processor instanceof DataServerListener) {
468
				((DataServerListener) _processor).dataServerExited();
469
			}
470
		}
471
472
		public void shutdown() {
473
			// interrupt(); // Bug 90153
474
		}
475
476
	} /* end class RingBufferFiller */
477
478
	/**
479
	 * 
480
	 * @author slavescu
481
	 * 
482
	 */
483
	class TCPDataProcessorNew extends TCPDataProcessor {
484
		protected ExtendedDataServerListener _extendedProcessor;
485
		protected DataProcessor _processor;
486
		// protected int _currentProcessingOffset;
487
		protected InetAddress _currentBufferAddr;
488
		protected byte[] _currentBufferData;
489
		protected int _currentBufferLength;
490
		protected long _currentMessageLength;
491
		protected byte _currentMessageType;
492
		protected int _currentHeaderOffset;
493
		protected char[] _stringForwardBuffer;
494
		protected byte[] _binaryForwardBuffer;
495
		protected int _bytesWritten;
496
		protected int _bytesRead;
497
		protected boolean _useExtendedProcessor;
498
		protected int _processed;
499
		protected byte[] _copyBuffer; // used only when the processor doesn't implement ExtendedDataServerListener
500
		protected boolean crimsonParser;
501
		protected boolean breakOuter;
502
		protected byte[] _inputStreamModeBuffer;
503
		protected int _inputStreamModeBufferLength, _inputStreamModeRecieverBufferLength;
504
		protected int _inputStreamModeBufferPos;
505
506
		public TCPDataProcessorNew() {
507
			super();
508
		}
509
510
		public void run() {
511
			crimsonParser = isCrimsonParser();
512
			if (CommunicationDebug.INSTANCE.debugMessageValue) {
513
				MESSAGE_VALUE_ID = MESSAGE_VALUE_ID + "_newDataProcessor_debugMessageValue_" + this.hashCode();
514
			}
515
			// else
516
			// if(CommunicationDebug.INSTANCE.debugSocketInputStream)
517
			// {
518
			// MESSAGE_VALUE_ID=MESSAGE_VALUE_ID+"_newDataProcessor_debugSocketInputStream"+this.hashCode();
519
			// }
520
521
			_isDataServerRunning = true; // Bug 90153
522
			_currentBufferData = new byte[BUFFER_SIZE];
523
			initLocalVariables();
524
			if (_processor instanceof ExtendedDataServerListener) {
525
				_useExtendedProcessor = true;
526
				_extendedProcessor = (ExtendedDataServerListener) _processor;
527
			} else
528
				_copyBuffer = new byte[BUFFER_SIZE];
529
530
			/* Run forever */
531
			outer: while (!_shutdown && _isDataServerRunning) { /* 9707 */
532
				if (CommunicationDebug.INSTANCE.debug) {
533
					System.out.println("TCPDataServerNew.run(): step outer while loop!");
534
				}
535
				if (isProcessing()) {
536
					_dataConnection.create();
537
					InputStream is;
538
					do {
539
						is = _dataConnection.getInputStream();
540
						if (is == null) {
541
							try {
542
								Thread.sleep(1000);
543
							} catch (InterruptedException e) {
544
								e.printStackTrace();
545
							}
546
						}
547
					} while (!_shutdown && (is == null));
548
549
					if (_shutdown) {
550
						return;
551
					}
552
553
					_currentBufferAddr = _dataConnection.getAddress();
554
555
					if (!CommunicationDebug.INSTANCE.debugUseEventMode && _useExtendedProcessor && !crimsonParser) {
556
						_inputStreamModeBuffer = new byte[BUFFER_SIZE];
557
						final InputStream delegatedInputStream = is;
558
						InputStream isFiltered = new InputStream() {
559
							byte[] oneByte = new byte[1];
560
561
							public int available() throws IOException {
562
								return delegatedInputStream.available();
563
							}
564
565
							public void close() throws IOException {
566
								delegatedInputStream.close();
567
							}
568
569
							public synchronized void mark(int readlimit) {
570
								delegatedInputStream.mark(readlimit);
571
							}
572
573
							public boolean markSupported() {
574
								return delegatedInputStream.markSupported();
575
							}
576
577
							public int read(byte[] b) throws IOException {
578
								return read(b, 0, b.length);
579
							}
580
581
							public synchronized void reset() throws IOException {
582
								delegatedInputStream.reset();
583
							}
584
585
							public long skip(long n) throws IOException {
586
								return delegatedInputStream.skip(n);
587
							}
588
589
							public synchronized int read(byte[] b, int off, int len) throws IOException {
590
								while (true) {
591
									if (_inputStreamModeBufferPos != _inputStreamModeBufferLength) {
592
										int ret = copyInputData(b, off, len);
593
										return ret;
594
									} else {
595
										_inputStreamModeBufferPos = 0;
596
										_inputStreamModeBufferLength = 0;
597
									}
598
599
									if (_currentBufferLength == _currentBufferData.length) {
600
										breakOuter = false;
601
										extendBuffer();
602
										if (breakOuter)
603
											return -1;
604
									}
605
									_bytesRead = delegatedInputStream.read(_currentBufferData, _currentBufferLength, _currentBufferData.length - _currentBufferLength);
606
									if (_bytesRead > 0) {
607
										if (CommunicationDebug.INSTANCE.debugMessageValue) {
608
											CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID, _currentBufferData, _currentBufferLength, _bytesRead);
609
										}
610
										_currentBufferLength += _bytesRead;
611
										// check if the header was received
612
										if (_currentBufferLength > MESSAGE_HEADER_LENGTH) {
613
											processCurrentBuffer();
614
											int ret = copyInputData(b, off, len);
615
											if (ret == 0)
616
												continue;
617
											return ret;
618
										}
619
									} else if (_bytesRead < 0) {
620
										/* The connection is closed */
621
										done(_dataConnection);
622
										return -1;
623
									}
624
									return 0;
625
								}
626
							}
627
628
							protected int copyInputData(byte[] b, int off, int len) {
629
								int ret = 0;
630
								len = Math.min(len, _inputStreamModeBufferLength - _inputStreamModeBufferPos);
631
								System.arraycopy(_inputStreamModeBuffer, _inputStreamModeBufferPos, b, off, len);
632
								// if(CommunicationDebug.INSTANCE.debugMessageValue)
633
								// {
634
								// CommunicationDebug.INSTANCE.writeBinaryLog("incommingData", b,off,len);
635
								// }
636
								_inputStreamModeBufferPos += len;
637
								return ret + len;
638
							}
639
640
							public int read() throws IOException {
641
								if (read(oneByte, 0, 1) == -1)
642
									return -1;
643
								else
644
									return oneByte[0];
645
							}
646
						};
647
						try {
648
							_extendedProcessor.incommingStream(isFiltered, _currentBufferAddr);
649
						} catch (Exception e) {
650
							if (CommunicationDebug.INSTANCE.debug) {
651
								System.out.println("TCPDataProcessorNew.run() - _extendedProcessor.incommingStream ended with exception, " + _extendedProcessor);
652
								e.printStackTrace(System.out);
653
							}
654
							done(_dataConnection);
655
							break outer;
656
						}
657
						if (CommunicationDebug.INSTANCE.debug) {
658
							System.out.println("TCPDataProcessorNew.run() - _extendedProcessor.incommingStream ended, " + _extendedProcessor);
659
						}
660
					} else
661
						while (true) {
662
							try {
663
								// if(CommunicationDebug.INSTANCE.debugSocketInputStream)
664
								// {
665
								// _bytesRead = is.read(_currentBuffer.data, 0, _currentBuffer.data.length);
666
								// if(_bytesRead>0)
667
								// CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID,_currentBuffer.data,0,_bytesRead);
668
								// else {
669
								// /* The connection is closed */
670
								// done(incommingConnection);
671
								// break outer;
672
								// }
673
								// }
674
								// else
675
								// {
676
								if (_processed != 0 && _currentMessageLength > Integer.MAX_VALUE) {
677
									_currentHeaderOffset = 0;
678
									recover();
679
									continue;
680
								} else {
681
									if (_currentBufferLength == _currentBufferData.length) {
682
										breakOuter = false;
683
										extendBuffer();
684
										if (breakOuter)
685
											break outer;
686
									}
687
									// if(CommunicationDebug.INSTANCE.debug)
688
									// {
689
									// System.out.println("TCPDataProcessorNew.run() - about to read _currentBufferData.length - _currentBufferLength="+(_currentBufferData.length - _currentBufferLength));
690
									// }
691
									_bytesRead = is.read(_currentBufferData, _currentBufferLength, _currentBufferData.length - _currentBufferLength);
692
									// if(CommunicationDebug.INSTANCE.debug)
693
									// {
694
									// System.out.println("TCPDataProcessorNew.run() - bytesRead="+_bytesRead);
695
									// }
696
									if (_bytesRead > 0) {
697
										if (CommunicationDebug.INSTANCE.debugMessageValue) {
698
											CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID, _currentBufferData, _currentBufferLength, _bytesRead);
699
										}
700
										_currentBufferLength += _bytesRead;
701
										// check if the header was received
702
										if (_currentBufferLength > MESSAGE_HEADER_LENGTH) {
703
											_processed = 0;
704
											processCurrentBuffer();
705
										}
706
									} else if (_bytesRead < 0) {
707
										/* The connection is closed */
708
										done(_dataConnection);
709
										break outer;
710
									}
711
								}
712
								// }
713
							} catch (InterruptedIOException e) {
714
								if (CommunicationDebug.INSTANCE.debug) {
715
									System.out.println("TCPDataProcessorNew.run() - timeout e.bytesTransferred=" + e.bytesTransferred);
716
									e.printStackTrace(System.out);
717
								}
718
								/* Read timeout, don't want to wait too long */
719
								/* This is used to terminate the thread if the process is killed abnormally */
720
								if (e.bytesTransferred > 0) {
721
									_bytesRead = e.bytesTransferred;
722
									if (CommunicationDebug.INSTANCE.debugMessageValue) {
723
										CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID, _currentBufferData, _currentBufferLength, _bytesRead);
724
									}
725
									_currentBufferLength += _bytesRead;
726
									// check if the header was received
727
									if (_currentBufferLength > MESSAGE_HEADER_LENGTH) {
728
										_processed = 0;
729
										processCurrentBuffer();
730
									}
731
732
								}
733
								// else
734
								// if(_shutdown)
735
								// {
736
								// /* The connection is closed */
737
								// done(incommingConnection);
738
								// break outer;
739
								// }
740
							} catch (IOException e) {
741
								if (CommunicationDebug.INSTANCE.debug) {
742
									e.printStackTrace(System.out);
743
								}
744
								done(_dataConnection);
745
								break outer;
746
							}
747
748
						}
749
				} else {
750
					try {
751
						if (CommunicationDebug.INSTANCE.debug) {
752
							System.out.println("TCPDataProcessorNew.run() - Monitoring is stopped, keep this thread in sleep state !");
753
						}
754
						/* Monitoring is stopped, keep this thread in sleep state */
755
						sleep(1000); /* 9707 */
756
					} catch (InterruptedException e) {
757
					}
758
				}
759
			}
760
			if (CommunicationDebug.INSTANCE.debug) {
761
				System.out.println("TCPDataServerNew.run(): exited outter while loop!");
762
			}
763
764
			if (CommunicationDebug.INSTANCE.debug) {
765
				System.out.println("TCPDataProcessorNew.run() - Close socket !");
766
			}
767
			_dataConnection.destroyConnection();
768
769
			if (_processor instanceof DataServerListener) {
770
				((DataServerListener) _processor).dataServerExited();
771
			}
772
			if (CommunicationDebug.INSTANCE.debugMessageValue) {
773
774
				try {
775
					CommunicationDebug.INSTANCE.getBinaryLog(MESSAGE_VALUE_ID).flush();
776
					CommunicationDebug.INSTANCE.removeBinaryLog(MESSAGE_VALUE_ID);
777
				} catch (IOException e) {
778
					// TODO Auto-generated catch block
779
					e.printStackTrace();
780
				}
781
			}
782
783
		}
784
785
		private void extendBuffer() {
786
			int remainingData = _currentBufferLength - _currentHeaderOffset;
787
			if (_currentMessageLength > _currentBufferLength - MESSAGE_HEADER_LENGTH) {
788
				// grow to _currentMessageLength+MESSAGE_HEADER_LENGTH
789
				byte[] b = null;
790
				try {
791
					b = new byte[(int) _currentMessageLength + MESSAGE_HEADER_LENGTH];
792
				} catch (Throwable e) {
793
					if (CommunicationDebug.INSTANCE.debug) {
794
						System.out.println("_currentHeaderOffset=" + _currentHeaderOffset);
795
						System.out.println("_currentBufferLength=" + _currentBufferLength);
796
						System.out.println("getMessageLength()=" + getMessageLength());
797
						System.out.println("getMessageType()=" + getMessageType());
798
						e.printStackTrace(System.out);
799
						// dump current buffer in a separate file
800
						CommunicationDebug.INSTANCE.writeBinaryLog(MESSAGE_VALUE_ID + "_" + _currentHeaderOffset, _currentBufferData, 0, _currentBufferLength);
801
					}
802
					// recover();
803
					// continue;
804
					breakOuter = true;
805
					return;
806
				}
807
				// copy remainig data to new location
808
				System.arraycopy(_currentBufferData, _currentHeaderOffset, b, 0, _currentBufferLength - _currentHeaderOffset);
809
				_currentBufferData = b;
810
			} else {
811
				if (remainingData < _currentHeaderOffset) {
812
					// shift remainig data to the begining of the buffer
813
					System.arraycopy(_currentBufferData, _currentHeaderOffset, _currentBufferData, 0, remainingData);
814
				} else {
815
					// shift remainig data to the begining of the buffer
816
					for (int i = 0; i < remainingData; i++) {
817
						_currentBufferData[i] = _currentBufferData[i + _currentHeaderOffset];
818
					}
819
				}
820
			}
821
			_currentBufferLength = remainingData;
822
			_currentHeaderOffset = 0;
823
		}
824
825
		protected boolean isCrimsonParser() {
826
			SAXParserFactory factory = SAXParserFactory.newInstance();
827
			try {
828
				SAXParser p = factory.newSAXParser();
829
				;
830
				if (p != null && p.getClass().getName().equals("org.apache.crimson.jaxp.SAXParserImpl")) {
831
					return true;
832
				}
833
			} catch (Exception e) {
834
			}
835
			return false;
836
		}
837
838
		private void done(DataConnection connection) {
839
			if (CommunicationDebug.INSTANCE.debug) {
840
				System.out.println("TCPDataServerNew.done(): entered - " + this);
841
			}
842
			/* Socket is toast or connection closed , we are done */
843
			pauseProcessing();
844
			_isDataServerRunning = false; // Bug 90153
845
			connection.destroyConnection(); /* 9707 */
846
			if (CommunicationDebug.INSTANCE.debug) {
847
				new Throwable("TCPDataServerNew.done(): Connection closed ! " + this).printStackTrace(System.out);
848
			}
849
		}
850
851
		protected int recover() {
852
			_currentHeaderOffset++;
853
			if (CommunicationDebug.INSTANCE.debug) {
854
				System.out.println("TCPDataServerNew.recover(): _currentHeaderOffset = " + _currentHeaderOffset);
855
			}
856
			// incorrect length, try to recover
857
			if (_currentHeaderOffset == _currentBufferLength) {
858
				// ignore this buffer and continue reading
859
				initLocalVariables();
860
				_currentHeaderOffset = 0;
861
			} else {
862
				_currentMessageLength = -1;
863
				_processed = 0;
864
				// process from new possition
865
				processCurrentBuffer();
866
			}
867
			return _currentHeaderOffset;
868
		}
869
870
		private void initLocalVariables() {
871
			_currentHeaderOffset = 0;
872
			_currentMessageLength = -1;
873
			_bytesRead = 0;
874
			_bytesWritten = 0;
875
			_currentBufferLength = 0;
876
			_processed = 0;
877
		}
878
879
		public void setProcessor(DataProcessor processor) {
880
			if (_processor instanceof ExtendedDataServerListener) {
881
				_useExtendedProcessor = true;
882
				_extendedProcessor = (ExtendedDataServerListener) _processor;
883
			} else {
884
				_useExtendedProcessor = false;
885
				this._processor = processor;
886
				if (_copyBuffer == null)
887
					_copyBuffer = new byte[BUFFER_SIZE];
888
			}
889
		}
890
891
		/**
892
		 * Get the length of the current message
893
		 */
894
		protected long getMessageLength() {
895
			return Message.readRALongFromBuffer(_currentBufferData, _currentHeaderOffset + 5);
896
		}
897
898
		/**
899
		 * Get the message type. There are currently three types of messages. BINARY_DATA, UTF8_STRING_DATA, UNICODE_STRING_DATA.
900
		 */
901
		protected byte getMessageType() {
902
			return _currentBufferData[_currentHeaderOffset + 9];
903
		}
904
905
		/**
906
		 * Check the message magic number. If the magic number is incorrect we need to go into recovery mode
907
		 */
908
		protected boolean checkMessageMagic() {
909
			// /* Check the message magic number */
910
			// long messageKey = (long) (_currentBufferData[_currentHeaderOffset] << 24 & 0xff000000) |
911
			// (long) (_currentBufferData[_currentHeaderOffset + 1] << 16 & 0x00ff0000) |
912
			// (long) _currentBufferData[_currentHeaderOffset + 2] << 8 & 0x0000ff00 |
913
			// (long) _currentBufferData[_currentHeaderOffset + 3];
914
			// /* If the magic is incorect we need to go into recovery mode */
915
			// /* TO_DO: RE-enable and test*/
916
			// if (messageKey == RA_MAGIC ) {
917
			// return false;
918
			// }
919
			// return Message.readRALongFromBuffer(_currentBufferData, _currentHeaderOffset) == RA_MAGIC ;
920
			if (_currentBufferData[_currentHeaderOffset] != RA_MAGIC_0)
921
				return false;
922
			if (_currentBufferData[_currentHeaderOffset + 1] != RA_MAGIC_1)
923
				return false;
924
			if (_currentBufferData[_currentHeaderOffset + 2] != RA_MAGIC_2)
925
				return false;
926
			if (_currentBufferData[_currentHeaderOffset + 3] != RA_MAGIC_3)
927
				return false;
928
			return true;
929
		}
930
931
		/**
932
		 * process the current input buffer and sends all the full messages to the data processor
933
		 */
934
		protected void processCurrentBuffer() {
935
			/* Is there data to process */
936
			if (_currentBufferLength <= 0) {
937
				_processed = 0;
938
				return;
939
			}
940
			int _stopProcessingMarker = _currentBufferLength - MESSAGE_HEADER_LENGTH;
941
			do {
942
				if (_currentMessageLength < 0) {
943
					/* Validate the message header */
944
					do {
945
						if (_currentHeaderOffset > _stopProcessingMarker) {
946
							_processed = 0;
947
							return;
948
						}
949
						if (checkMessageMagic()) {
950
							break;
951
						}
952
						// recovery mode, try and look at the next offset
953
						if (CommunicationDebug.INSTANCE.debug)
954
							System.out.println("TCPDataServerNew.processCurrentBuffer() - Invalid magic number in header at: " + _currentHeaderOffset);
955
						_currentHeaderOffset++;
956
					} while (true);
957
					_currentMessageLength = getMessageLength();
958
					_currentMessageType = getMessageType();
959
				}
960
				if (_currentHeaderOffset + _currentMessageLength <= _stopProcessingMarker) {
961
					_bytesWritten = writeMessage(_currentHeaderOffset, _currentBufferData);
962
					_processed += _bytesWritten;
963
					_currentHeaderOffset = _currentHeaderOffset + MESSAGE_HEADER_LENGTH + _bytesWritten;
964
					// _currentMessageLength = -1;
965
				} else {
966
					return;
967
				}
968
			} while (true);
969
		}
970
971
		/**
972
		 * sends a full message to the data processor
973
		 */
974
		protected int writeMessage(int _currentHeaderOffset, byte[] _currentBufferData) {
975
			int _bytesWritten = 0;
976
			if (_currentMessageType == UNICODE_STRING_DATA) {
977
				int endOffset = _currentHeaderOffset + MESSAGE_HEADER_LENGTH + (int) _currentMessageLength;
978
				for (int i = _currentHeaderOffset + MESSAGE_HEADER_LENGTH; i < endOffset;) {
979
					_stringForwardBuffer[_bytesWritten >> 1] = (char) ((char) _currentBufferData[i++] | (char) (_currentBufferData[i++] << 8));
980
					_bytesWritten += 2;
981
982
				}
983
				/* Are we at the end of the message? If so forward to the handler */
984
				if (_bytesWritten == _currentMessageLength) {
985
					_processor.incommingData(_stringForwardBuffer, _bytesWritten, _currentBufferAddr);
986
					_currentMessageLength = -1;
987
					// _bytesWritten = 0;
988
					// _currentHeaderOffset = 0;
989
					// /* Continue processing this data buffer */
990
					// current = this.processData(data, current, limit, addr);
991
				}
992
993
			} else {
994
				_bytesWritten = (int) _currentMessageLength;
995
				if (_useExtendedProcessor) {
996
					if (!CommunicationDebug.INSTANCE.debugUseEventMode && !crimsonParser) {
997
						if (_inputStreamModeBuffer.length - _inputStreamModeBufferLength < _bytesWritten) {
998
							byte[] temp = new byte[_inputStreamModeBufferLength + _bytesWritten + 1024];
999
							System.arraycopy(_inputStreamModeBuffer, 0, temp, 0, _inputStreamModeBufferLength);
1000
							_inputStreamModeBuffer = temp;
1001
						}
1002
						System.arraycopy(_currentBufferData, _currentHeaderOffset + MESSAGE_HEADER_LENGTH, _inputStreamModeBuffer, _inputStreamModeBufferLength, _bytesWritten);
1003
						_inputStreamModeBufferLength += _bytesWritten;
1004
					} else
1005
						_extendedProcessor.incommingData(_currentBufferData, _currentHeaderOffset + MESSAGE_HEADER_LENGTH, _bytesWritten, _currentBufferAddr);
1006
				} else {
1007
					/* BINARY_DATA, UTF8_STRING_DATA or Invalid message type */
1008
					/* Copy as many bytes as possible into the forwarding buffer */
1009
					if (_copyBuffer.length < _bytesWritten)
1010
						_copyBuffer = new byte[_bytesWritten];
1011
					System.arraycopy(_currentBufferData, _currentHeaderOffset + MESSAGE_HEADER_LENGTH, _copyBuffer, 0, _bytesWritten);
1012
					_processor.incommingData(_copyBuffer, _bytesWritten, _currentBufferAddr);
1013
				}
1014
				_currentMessageLength = -1;
1015
			}
1016
			return _bytesWritten;
1017
		}
1018
1019
		public void shutdown() {
1020
			if (CommunicationDebug.INSTANCE.debug) {
1021
				System.out.println("TCPDataServerNew.shutdown() - " + this);
1022
			}
1023
			_shutdown = true;
1024
			_dataConnection.destroyConnection();
1025
		}
1026
1027
	} /* end class TCPDataProcessorNew */
1028
1029
	public int getPort() {
1030
		return _port;
1031
	}
1032
1033
	public void startLocalServer(DataProcessor processor) throws IOException {
1034
		int instance = Integer.parseInt(_dataConnection.getConnectionId());
1035
		startServer(processor, -instance); // pass in negative port for local direct instance name
1036
	}
1037
1038
	public void startServer(DataProcessor processor, int port) throws IOException {
1039
		if (!CommunicationDebug.INSTANCE.debugUseOldDataServer) {
1040
			startServerNew(processor, port);
1041
		} else {
1042
			/* Create the buffering mechanism */
1043
			_bufferArray = new SingleBuffer[NUM_BUFFERS];
1044
			for (int i = 0; i < NUM_BUFFERS; i++)
1045
				_bufferArray[i] = new SingleBuffer();
1046
1047
			_port = _dataConnection.getPort();
1048
1049
			_server = new TCPDataProcessor();
1050
			_server.setName("TCPDataFiller");
1051
1052
			/* Set up the data flusher */
1053
			_flusher = new BufferFlusher();
1054
			_flusher.setProcessor(processor);
1055
			_flusher.setName("TCPDataFlusher");
1056
1057
			/* Don't block exit of the VM */
1058
			_server.setDaemon(true);
1059
			_flusher.setDaemon(true);
1060
1061
			/*
1062
			 * RKD: Because these two threads intensely contend for the same resources we need to increase the priority of the flusher, otherwise I have noticed that the flusher doesn't run often enough and the data sits in the buffers far too long. A relitive increase of 3 seems to much better
1063
			 */
1064
1065
			_flusher.setPriority(_server.getPriority() + 3);
1066
1067
			_server.start();
1068
			_flusher.start();
1069
		}
1070
	}
1071
1072
	private void startServerNew(DataProcessor processor, int port) throws IOException {
1073
		/* Create the buffering mechanism */
1074
		_bufferArray = new SingleBuffer[NUM_BUFFERS];
1075
		for (int i = 0; i < NUM_BUFFERS; i++) {
1076
			_bufferArray[i] = new SingleBuffer();
1077
		}
1078
1079
		_server = new TCPDataProcessorNew();
1080
		_server.setName("TCPDataFiller");
1081
		((TCPDataProcessorNew) _server).setProcessor(processor);
1082
1083
		/* Don't block exit of the VM */
1084
		_server.setDaemon(true);
1085
1086
		_server.start();
1087
	}
1088
1089
	public void startServer(DataProcessor processor) throws IOException {
1090
		startServer(processor, 0);
1091
	}
1092
1093
	public boolean isProcessing() {
1094
		return _isDataServerRunning; // Bug 90153
1095
		// return _server.isAlive();
1096
	}
1097
1098
	public void stopServer() {
1099
		_server.pauseProcessing(); /* 9707 */
1100
	}
1101
1102
	/* 9707 */
1103
	public void resumeServer() {
1104
		_server.resumeProcessing();
1105
	}
1106
1107
	/* 9707 */
1108
	public void resumeServer(DataProcessor processor) {
1109
		if (!CommunicationDebug.INSTANCE.debugUseOldDataServer) {
1110
			resumeServerNew(processor);
1111
		} else {
1112
			_flusher.setProcessor(processor);
1113
			_server.resumeProcessing();
1114
		}
1115
	}
1116
1117
	private void resumeServerNew(DataProcessor processor) {
1118
		_server.resumeProcessing();
1119
		((TCPDataProcessorNew) _server).setProcessor(processor);
1120
	}
1121
1122
	/* 9707 */
1123
	public void shutdownServer() {
1124
		// System.out.println("TCPDataServer is shutted down!");
1125
		if (!CommunicationDebug.INSTANCE.debugUseOldDataServer) {
1126
			shutdownServerNew();
1127
		} else {
1128
			_server.shutdown();
1129
			_flusher.shutdown();
1130
		}
1131
	}
1132
1133
	private void shutdownServerNew() {
1134
		_server.shutdown();
1135
	}
1136
1137
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentDetailsCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentDetailsCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentDetailsCommand extends DetailedAgentInfoCommand {
16
17
	/**
18
	 * ReadyVMCommand constructor comment.
19
	 */
20
	public AgentDetailsCommand() {
21
		super();
22
		_tag = RA_AGENT_DETAILS;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ProcessActiveException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessActiveException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class ProcessActiveException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = -6533768583180265869L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/DetachFromAgentCommand.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DetachFromAgentCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class DetachFromAgentCommand extends SimpleAgentInfoCommand {
16
17
	/**
18
	 * DetachFromCommand constructor comment.
19
	 */
20
	public DetachFromAgentCommand() {
21
		super();
22
		_tag = RA_DETACH_FROM_AGENT;
23
	}
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/RAInetAddress.java (+70 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: RAInetAddress.java,v 1.3 2005/04/05 15:48:58 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
import java.net.UnknownHostException;
17
18
public class RAInetAddress implements Constants {
19
20
	protected byte[] _data = null;
21
	protected int _length = 0;
22
	protected InetAddress _address = null;
23
24
	public RAInetAddress() {
25
		super();
26
	}
27
28
	public int getLength() {
29
		return _length;
30
	}
31
32
	public void setLength(int length) {
33
		_length = length;
34
	}
35
36
	public void setData(byte[] data) {
37
		_data = data;
38
	}
39
40
	public int getSize() {
41
		return sizeofByte + _length;
42
	}
43
44
	public InetAddress getAddress() throws UnknownHostException {
45
		/* Check our cache */
46
		if (_address != null) {
47
			return _address;
48
		}
49
50
		if (_length == 0) {
51
			return null;
52
		}
53
		/* Build a string representing the IP address in decimal form */
54
		String addr = new String();
55
		addr += Byte.toString(_data[0]);
56
		for (int i = 1; i < _length; i++) {
57
			addr = addr + "." + Byte.toString(_data[i]);
58
		}
59
60
		/* Lookup all the InetAddress objects for this address */
61
		InetAddress addrs = InetAddress.getByName(addr);
62
63
		/*
64
		 * Search for our match: RKD: This was removed aswe probablydon't need all the addresses. for(int j=0; j<addrs.length; j++) { if(addrs[j].getHostAddress().equals(addr)) { _address=addrs[j]; return _address; } } return null
65
		 */
66
67
		return addrs;
68
	}
69
70
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Variable.java (+43 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Variable.java,v 1.3 2005/04/05 15:48:58 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
/**
16
 * A Variable maps to an instance of a environment variable
17
 */
18
public class Variable {
19
	private String _name = null;
20
	private String _value = null;
21
22
	/**
23
	 * Create an environment variable with the specified name value pair.
24
	 */
25
	public Variable(String name, String value) {
26
		_name = name;
27
		_value = value;
28
	}
29
30
	/**
31
	 * Retrieve the name of this environment variable.
32
	 */
33
	public String getName() {
34
		return _name;
35
	}
36
37
	/**
38
	 * Retrieve the value of this environment variable.
39
	 */
40
	public String getValue() {
41
		return _value;
42
	}
43
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentPeerListener.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentPeerListener.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public interface AgentPeerListener extends AgentListener {
16
17
	/**
18
	 * Invoked when an agent requests to be monitored because this client is currently monitoring another agent.
19
	 */
20
	void peerWaiting(Agent agent, Agent peer);
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/StartMonitoringRemoteAgentCommand.java (+117 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: StartMonitoringRemoteAgentCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.net.InetAddress;
16
17
public class StartMonitoringRemoteAgentCommand extends SimpleAgentInfoCommand {
18
19
	protected long _port = 0;
20
	protected long _ip = 0;
21
22
	/**
23
	 * SetMonitorCommandEntry constructor comment.
24
	 */
25
	public StartMonitoringRemoteAgentCommand() {
26
		super();
27
		_tag = RA_START_MONITORING_AGENT_REMOTE;
28
	}
29
30
	/**
31
	 * Insert the method's description here. Creation date: (11/3/00 11:06:34 AM)
32
	 */
33
	public long getIP() {
34
		return _ip;
35
	}
36
37
	/**
38
	 * Insert the method's description here. Creation date: (6/8/00 12:23:51 PM)
39
	 * 
40
	 * @return short
41
	 */
42
	public long getPort() {
43
		return _port;
44
	}
45
46
	/**
47
	 * Insert the method's description here. Creation date: (6/8/00 12:58:48 PM)
48
	 * 
49
	 * @return int
50
	 */
51
	public int getSize() {
52
		return super.getSize() + 2 * sizeofLong;
53
	}
54
55
	/**
56
	 * Insert the method's description here. Creation date: (9/11/00 9:25:14 PM)
57
	 * 
58
	 * @return int
59
	 * @param buffer
60
	 *            byte[]
61
	 * @param length
62
	 *            int[]
63
	 */
64
	public int readFromBuffer(byte[] buffer, int offset) {
65
		int current = super.readFromBuffer(buffer, offset);
66
67
		_ip = Message.readRALongFromBuffer(buffer, current);
68
		current += sizeofLong;
69
70
		_port = Message.readRALongFromBuffer(buffer, current);
71
		current += sizeofLong;
72
73
		return current;
74
	}
75
76
	/**
77
	 * Insert the method's description here. Creation date: (11/3/00 11:06:19 AM)
78
	 * 
79
	 * @param param
80
	 *            java.net.InetAddress
81
	 */
82
	public void setInetAddress(InetAddress param) {
83
		byte[] addr_bytes = param.getAddress();
84
		_ip = 0;
85
		_ip += (addr_bytes[3] << 24) & (0xFF000000);
86
		_ip += (addr_bytes[2] << 16) & (0x00FF0000);
87
		_ip += (addr_bytes[1] << 8) & (0x0000FF00);
88
		_ip += (addr_bytes[0]) & (0x000000FF);
89
	}
90
91
	/**
92
	 * Insert the method's description here. Creation date: (6/8/00 12:23:41 PM)
93
	 * 
94
	 * @param port
95
	 *            short
96
	 */
97
	public void setPort(short port) {
98
		_port = port;
99
	}
100
101
	/**
102
	 * Insert the method's description here. Creation date: (7/21/00 3:41:09 PM)
103
	 * 
104
	 * @return int
105
	 * @param buffer
106
	 *            byte[]
107
	 * @param offset
108
	 *            int
109
	 */
110
	public int writeToBuffer(byte[] buffer, int offset) {
111
		int current = super.writeToBuffer(buffer, offset);
112
		current = Message.writeRALongToBuffer(buffer, current, _ip);
113
		current = Message.writeRALongToBuffer(buffer, current, _port);
114
115
		return current;
116
	}
117
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ConsoleNotStartedException.java (+38 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ConsoleNotStartedException.java,v 1.4 2005/10/08 14:28:53 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class ConsoleNotStartedException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = -3830340454438462679L;
21
22
	/**
23
	 * ConsoleNotStartedException constructor comment.
24
	 */
25
	public ConsoleNotStartedException() {
26
		super();
27
	}
28
29
	/**
30
	 * ConsoleNotStartedException constructor comment.
31
	 * 
32
	 * @param s
33
	 *            java.lang.String
34
	 */
35
	public ConsoleNotStartedException(String s) {
36
		super(s);
37
	}
38
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/NodeImpl.java (+776 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: NodeImpl.java,v 1.20 2006/12/14 23:11:18 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.net.InetAddress;
17
import java.net.InetSocketAddress;
18
import java.net.ServerSocket;
19
import java.net.UnknownHostException;
20
import java.util.Enumeration;
21
import java.util.Hashtable;
22
23
import org.eclipse.hyades.execution.security.ISecureClientParameters;
24
import org.eclipse.hyades.execution.local.common.ActiveAgentListCommand;
25
import org.eclipse.hyades.execution.local.common.AgentDetailsCommand;
26
import org.eclipse.hyades.execution.local.common.CommandElement;
27
import org.eclipse.hyades.execution.local.common.Constants;
28
import org.eclipse.hyades.execution.local.common.ControlMessage;
29
import org.eclipse.hyades.execution.local.common.GetPropertyListCommand;
30
import org.eclipse.hyades.execution.local.common.KillProcessCommand;
31
import org.eclipse.hyades.execution.local.common.MonitorPeerRequestCommand;
32
import org.eclipse.hyades.execution.local.common.PropertyListCommand;
33
import org.eclipse.hyades.execution.local.common.QueryAgentDetailsCommand;
34
import org.eclipse.hyades.execution.local.common.QueryAgentListCommand;
35
import org.eclipse.hyades.execution.local.common.QueryProcessListCommand;
36
import org.eclipse.hyades.execution.local.common.RegisteredProcessListCommand;
37
import org.eclipse.hyades.execution.local.common.SetNVPairCommand;
38
import org.eclipse.hyades.execution.local.common.SimpleProcessCommand;
39
import org.eclipse.hyades.execution.security.LoginFailedException;
40
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
41
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
42
import org.eclipse.hyades.execution.security.User;
43
import org.eclipse.tptp.platform.agentcontroller.internal.AgentControllerConstants;
44
import org.eclipse.tptp.platform.agentcontroller.internal.impl.AgentControllerFactoryImpl;
45
46
public class NodeImpl implements Node, Constants {
47
	private static int DEFAULT_TIMEOUT = 15000; // 15 sec
48
49
	private String _name;
50
51
	private InetAddress[] _addr;
52
53
	private Connection _connection;
54
55
	private Application _application;
56
57
	private Hashtable _processList = new Hashtable(256);
58
59
	private SetNVPairCommand[] props = null;
60
61
	// Local listeners and handlers
62
	private InnerProcessListener _processListener = new InnerProcessListener();
63
64
	private InnerConnectionListener _connectionListener = new InnerConnectionListener();
65
66
	private InnerCommandHandler _commandHandler = new InnerCommandHandler();
67
68
	// Locks
69
	private Object _processListLock = new Object();
70
71
	private Object _agentListLock = new Object();
72
73
	private Object _agentDetailsLock = new Object();
74
75
	private Object _propertyListLock = new Object();
76
77
	//
78
	// Security related stuff
79
	//
80
	private boolean _isAuthenticated = false;
81
	private int _authenticationTimeout = 10000; // 5 sec authentication timeout
82
	private Object _authenticationLock = new Object();
83
	private User _user = null;
84
	private ISecureClientParameters _securityParms = null;
85
86
	public NodeImpl(String name, InetAddress addr) {
87
		super();
88
		_name = name;
89
90
		try {
91
			_addr = InetAddress.getAllByName(addr.getHostName());
92
		} catch (UnknownHostException e) {
93
		}
94
	}
95
96
	public NodeImpl(String name, InetAddress[] addr) {
97
		super();
98
		_name = name;
99
		_addr = addr;
100
	}
101
102
	/**
103
	 * @see Node#killProcess(Process)
104
	 */
105
	public void killProcess(Process process) throws InactiveProcessException, NotConnectedException {
106
		/* Determine if we have a connection */
107
		if (_connection == null) {
108
			throw new NotConnectedException();
109
		}
110
111
		/* Determine if the process is active */
112
		if (!process.isActive()) {
113
			throw new InactiveProcessException();
114
		}
115
116
		/* Kill the process */
117
		ControlMessage message = new ControlMessage();
118
		KillProcessCommand command = new KillProcessCommand();
119
		command.setProcessId(Long.parseLong(process.getProcessId()));
120
		message.appendCommand(command);
121
		try {
122
			_connection.sendMessage(message, _commandHandler);
123
		} catch (IOException e) {
124
			// TODO Auto-generated catch block
125
		}
126
	}
127
128
	/**
129
	 * @see Node#shutdown(long)
130
	 */
131
	public void shutdown(long delay) throws NotConnectedException {
132
		throw new NotImplementedException();
133
	}
134
135
	/**
136
	 * @see Node#reboot(long)
137
	 */
138
	public void reboot(long delay) throws NotConnectedException {
139
		throw new NotImplementedException();
140
	}
141
142
	/**
143
	 * @see Node#listMonitors()
144
	 */
145
	public Enumeration listMonitors() throws NotConnectedException {
146
		throw new NotImplementedException();
147
	}
148
149
	/**
150
	 * List the processes running in the node
151
	 * 
152
	 * This method has side effects of setting the _processList member variable, populating the agents within each process in _processList and retrieving the details of each agent in each process.
153
	 */
154
	public Enumeration listProcesses() throws NotConnectedException {
155
		ControlMessage message;
156
157
		if (_connection == null) {
158
			throw new NotConnectedException();
159
		} else {
160
			_connection.addConnectionListener(_connectionListener); // to avoid
161
			// deadlock
162
163
			// Query the process list
164
			message = new ControlMessage();
165
			QueryProcessListCommand qplCommand = new QueryProcessListCommand();
166
			message.appendCommand(qplCommand);
167
			synchronized (_processListLock) {
168
				try {
169
					_connection.sendMessage(message, _commandHandler);
170
					_processListLock.wait(DEFAULT_TIMEOUT);
171
				} catch (Exception e) {
172
					e.printStackTrace();
173
					return null;
174
				}
175
			}
176
177
			// Populate the process with all agents
178
			Enumeration ePIDs = _processList.keys();
179
			while (ePIDs.hasMoreElements()) {
180
				Long pid = (Long) (ePIDs.nextElement());
181
				Process p = (ProcessImpl) _processList.get(pid);
182
183
				// Query the agent list
184
				message = new ControlMessage();
185
				QueryAgentListCommand qalCommand = new QueryAgentListCommand();
186
				qalCommand.setProcessId(pid.longValue());
187
				message.appendCommand(qalCommand);
188
				synchronized (_agentListLock) {
189
					try {
190
						_connection.sendMessage(message, _commandHandler);
191
						_agentListLock.wait(DEFAULT_TIMEOUT);
192
					} catch (Exception e) {
193
						e.printStackTrace();
194
						return null;
195
					}
196
				}
197
198
				// Populate the agent details
199
				Enumeration eAgents = p.listAgents();
200
				while (eAgents.hasMoreElements()) {
201
					Agent ag = (Agent) eAgents.nextElement();
202
					String agentName = ag.getName();
203
204
					message = new ControlMessage();
205
					QueryAgentDetailsCommand qadCommand = new QueryAgentDetailsCommand();
206
					qadCommand.setProcessId(pid.longValue());
207
					qadCommand.setAgentName(agentName);
208
					message.appendCommand(qadCommand);
209
					synchronized (_agentDetailsLock) {
210
						try {
211
							_connection.sendMessage(message, _commandHandler);
212
							_agentDetailsLock.wait(DEFAULT_TIMEOUT);
213
						} catch (Exception e) {
214
							e.printStackTrace();
215
							return null;
216
						}
217
					}
218
				}
219
			}
220
		}
221
222
		return _processList.elements();
223
	}
224
225
	/**
226
	 * @see Node#getProcess()
227
	 */
228
	public synchronized Process getProcess(String processId) {
229
		return (Process) _processList.get(new Long(processId));
230
	}
231
232
	/**
233
	 * @see Node#getInetAddress()
234
	 */
235
	public InetAddress getInetAddress() {
236
		if (_addr != null) {
237
			return _addr[0];
238
		}
239
240
		return null;
241
	}
242
243
	/**
244
	 * @see Node#getAllInetAddresses()
245
	 */
246
	public InetAddress[] getAllInetAddresses() {
247
		return _addr;
248
	}
249
250
	/**
251
	 * @see Node#getName()
252
	 */
253
	public String getName() {
254
		return _name;
255
	}
256
257
	/**
258
	 * @see Node#isConnected()
259
	 */
260
	public boolean isConnected() {
261
		if (_connection != null) {
262
			return _connection.isActive();
263
		}
264
		return false;
265
	}
266
267
	/**
268
	 * @see Node#connect()
269
	 */
270
	public synchronized Connection connect(int port) throws AgentControllerUnavailableException, SecureConnectionRequiredException, UntrustedAgentControllerException, LoginFailedException {
271
		Connection testConnection = null;
272
273
		/*
274
		 * Will try to connect if: 1. There is no connection 2. There is a connection but it is not active 3. There is a connection but wants to test other connections as well
275
		 */
276
		int who = AgentControllerFactoryImpl.whoIsRunning();
277
		if (isLocal() && ((port <= 0) || ((port > 0) && (who != AgentControllerConstants.TPTP_RAC_RUNNING)))) {
278
279
			/* If someone has a RAC running but choose IAC, throw an exception */
280
			if (who == AgentControllerConstants.TPTP_RAC_RUNNING) {
281
				throw new AgentControllerUnavailableException(); // Since IAC cannot be started if RAC is already running
282
			}
283
284
			if (!AgentControllerFactoryImpl.getAgentController().isEnabled()) {
285
				throw new AgentControllerUnavailableException(); // Since IAC is disabled by preference
286
			}
287
288
			/*
289
			 * Start IAC if not already started
290
			 */
291
			AgentControllerFactoryImpl.getAgentController().start();
292
293
			/*
294
			 * Reuse existing if there is ones, or it has a previously attached remote ConnectionImpl
295
			 */
296
			if ((_connection == null) || (_connection instanceof ConnectionImpl)) {
297
				_connection = ConnectionFactory.getLocalConnection(this);
298
			}
299
300
			/*
301
			 * Try connect
302
			 */
303
			if (!_connection.isActive()) {
304
				try {
305
					_connection.connect(this, 0);
306
				} catch (Exception e) {
307
					e.printStackTrace();
308
				}
309
			}
310
		} else if ((_connection == null || !_connection.isActive() || (port != _connection.getPort()))) { // Bug
311
			// 54320
312
			try {
313
314
				/*
315
				 * If the keystore is specified then we will try a secure connection
316
				 */
317
				if (_securityParms == null) {
318
					testConnection = ConnectionFactory.getConnection(this);
319
					testConnection.connect(this, port);
320
				} else {
321
					/* Look through our extension points for a security provider */
322
					testConnection = ConnectionFactory.getSecuredConnection(this);
323
					if (testConnection != null) {
324
						testConnection.connect(this, port);
325
					}
326
				}
327
328
				/*
329
				 * If there is no exception after calling connect() that means the connection with the specified port is valid. Since we assume a 1-to-1 association between Node and Connection, that means any previous connectio is invalid (otherwise the attempted connect() will fail).
330
				 */
331
				_connection = testConnection;
332
333
			} catch (IOException e) {
334
				_connection = null;
335
				throw new AgentControllerUnavailableException();
336
			}
337
		}
338
339
		return _connection;
340
341
	}
342
343
	/**
344
	 * @see Node#getConnection()
345
	 */
346
	public Connection getConnection() {
347
		if (_connection == null) {
348
			return null;
349
		}
350
351
		if (!_connection.isActive()) {
352
			if (_connection instanceof LocalConnectionImpl) {
353
				try {
354
					_connection.connect(this, 0);
355
				} catch (Exception e) {
356
				}
357
			}
358
		}
359
		return _connection;
360
	}
361
362
	public ProcessListener getProcessListener() {
363
		return _processListener;
364
	}
365
366
	/**
367
	 * @see Node#setUser()
368
	 */
369
	public void setUser(User user) {
370
		_user = user;
371
	}
372
373
	/**
374
	 * @see Node#getUser()
375
	 */
376
	public User getUser() {
377
		return _user;
378
	}
379
380
	public void setApplication(Application app) {
381
		_application = app;
382
	}
383
384
	public Application getApplication() {
385
		return _application;
386
	}
387
388
	public void setSecurityParameters(ISecureClientParameters manager) {
389
		_securityParms = manager;
390
	}
391
392
	public ISecureClientParameters getSecurityParameters() {
393
		return _securityParms;
394
	}
395
396
	/**
397
	 * Bug 53938
398
	 * 
399
	 * Query the options specified in the Agent Controller's configuration file.
400
	 * 
401
	 * @param name
402
	 *            The name of the option
403
	 * @param type
404
	 *            The type of the option
405
	 * @return An array of SetNVPairCommand objects
406
	 */
407
	public SetNVPairCommand[] getPropertyValues(String name, String type) throws NotConnectedException {
408
		/* Determine if we have a connection */
409
		if (_connection == null) {
410
			throw new NotConnectedException();
411
		}
412
413
		/* Request the process list from the client engine */
414
		ControlMessage message = new ControlMessage();
415
		GetPropertyListCommand command = new GetPropertyListCommand();
416
		command.setName(name);
417
		command.setType(type);
418
		message.appendCommand(command);
419
420
		synchronized (_propertyListLock) {
421
			try {
422
				_connection.sendMessage(message, _commandHandler);
423
				_propertyListLock.wait(DEFAULT_TIMEOUT);
424
			} catch (Exception e) {
425
				return null;
426
			}
427
		}
428
429
		return props;
430
	}
431
432
	/*
433
	 * (non-Javadoc)
434
	 * 
435
	 * Waits for a particular process to be present or the timeout value to be reached; after the process list returns (the internal process list in this node instance is updated) the process is retrieved via the get process method. The timeout value is approximate since there is some time needed to execute the various operations within the loop and each wait is done timeout divided by 2000 times. For example, a 60000 (60 second) timeout would cause the loop to execute 30 times and wait for 2 seconds at the end of each process list query.
436
	 * 
437
	 * The listProcesses(...) method default wait time itself is up to 7 seconds to receive the process list.
438
	 * 
439
	 */
440
	public synchronized Process waitForProcess(String processIdentity, int timeout) throws NotConnectedException, InactiveProcessException {
441
442
		// Change this from a polling model into a notify model
443
		try {
444
			for (int i = 0, j = timeout / 2000; i < j; i++) {
445
				Enumeration processes = this.fastListProcesses();
446
				if (processes != null) {
447
					for (; processes.hasMoreElements();) {
448
						Process process = (Process) processes.nextElement();
449
						if (process.getProcessId().equals(processIdentity)) {
450
							return process;
451
						}
452
					}
453
				}
454
				this.wait(2000);
455
			}
456
		} catch (InterruptedException e) {
457
			// Do not need to handle this
458
		}
459
460
		return null; // no process was found in the allowed time
461
	}
462
463
	/**
464
	 * List the processes running in the node
465
	 * 
466
	 * This method has side effects of setting the _processList member variable and populating the agents within each process in _processList Unlike the listProcesses() method, it does *not* retrieve the details for each agent.
467
	 */
468
	public Enumeration fastListProcesses() throws NotConnectedException {
469
		ControlMessage message;
470
471
		if (_connection == null) {
472
			throw new NotConnectedException();
473
		} else {
474
			_connection.addConnectionListener(_connectionListener); // to avoid
475
			// deadlock
476
477
			// Query the process list
478
			message = new ControlMessage();
479
			QueryProcessListCommand qplCommand = new QueryProcessListCommand();
480
			message.appendCommand(qplCommand);
481
			synchronized (_processListLock) {
482
				try {
483
					_connection.sendMessage(message, _commandHandler);
484
					_processListLock.wait(DEFAULT_TIMEOUT);
485
				} catch (Exception e) {
486
					e.printStackTrace();
487
					return null;
488
				}
489
			}
490
491
			// Populate the process with all agents
492
			Enumeration ePIDs = _processList.keys();
493
			while (ePIDs.hasMoreElements()) {
494
				Long pid = (Long) (ePIDs.nextElement());
495
496
				// Query the agent list
497
				message = new ControlMessage();
498
				QueryAgentListCommand qalCommand = new QueryAgentListCommand();
499
				qalCommand.setProcessId(pid.longValue());
500
				message.appendCommand(qalCommand);
501
				synchronized (_agentListLock) {
502
					try {
503
						_connection.sendMessage(message, _commandHandler);
504
						_agentListLock.wait(DEFAULT_TIMEOUT);
505
					} catch (Exception e) {
506
						e.printStackTrace();
507
						return null;
508
					}
509
				}
510
			}
511
512
		}
513
514
		return _processList.elements();
515
	}
516
517
	public void removeProcess(long pid) {
518
		if (_processList.containsKey(new Long(pid))) {
519
			_processList.remove(new Long(pid));
520
		}
521
	}
522
523
	/**
524
	 * Handler for default context (0)
525
	 */
526
	public void incommingCommand(Node node, CommandElement command) {
527
		_commandHandler.incommingCommand(node, command);
528
	}
529
530
	private boolean isLocal() {
531
		boolean isLocal = false;
532
533
		try {
534
			InetAddress localAddr = InetAddress.getLocalHost();
535
			for (int i = 0; i < _addr.length; i++) {
536
				if (localAddr.equals(_addr[i])) {
537
					isLocal = true;
538
				}
539
			}
540
		} catch (UnknownHostException e) {
541
		}
542
543
		return isLocal;
544
	}
545
546
	public boolean authenticateUser() {
547
		if (_user != null) {
548
			synchronized (_authenticationLock) {
549
				try {
550
					_user.login(_connection, _commandHandler);
551
					_authenticationLock.wait(_authenticationTimeout);
552
				} catch (InterruptedException e) {
553
					e.printStackTrace();
554
				} catch (IOException e) {
555
					e.printStackTrace();
556
				}
557
			}
558
		}
559
560
		return _isAuthenticated;
561
	}
562
563
	public boolean isUserAuthenticated() {
564
		return _isAuthenticated;
565
	}
566
567
	class InnerConnectionListener implements ConnectionListener {
568
		// If connection is lost, release all object locks
569
		public void connectionClosed(Connection connection) {
570
			synchronized (_processListLock) {
571
				_processListLock.notifyAll();
572
			}
573
			synchronized (_propertyListLock) {
574
				_propertyListLock.notifyAll();
575
			}
576
		}
577
	}
578
579
	class InnerCommandHandler implements CommandHandler {
580
		public void incommingCommand(Node node, CommandElement command) {
581
			int tag = (int) command.getTag();
582
			switch (tag) {
583
			case (int) Constants.RA_AUTHENTICATION_SUCCESSFUL:
584
				_isAuthenticated = true;
585
				synchronized (_authenticationLock) {
586
					_authenticationLock.notifyAll();
587
				}
588
				break;
589
			case (int) Constants.RA_AUTHENTICATION_FAILED:
590
				_isAuthenticated = false;
591
				synchronized (_authenticationLock) {
592
					_authenticationLock.notifyAll();
593
				}
594
				break;
595
			case (int) Constants.RA_PROCESS_LIST: {
596
				RegisteredProcessListCommand rplCmd = (RegisteredProcessListCommand) command;
597
				long[] pids = rplCmd.getProcessList();
598
599
				// _processList.clear(); // Dangerous!!! Will remove all agents information within the process
600
				// Clear the process list if there is no process registered
601
				if ((pids == null) || (pids.length == 0)) {
602
					_processList.clear();
603
				} else {
604
					// Compare the returned process list and remove any terminated process
605
					Enumeration e_tmp = _processList.keys();
606
					while (e_tmp.hasMoreElements()) {
607
						Long pidstr_tmp = (Long) e_tmp.nextElement();
608
						Process p_tmp = (Process) _processList.get(pidstr_tmp);
609
						try {
610
							long pid_tmp = Long.parseLong(p_tmp.getProcessId());
611
							boolean exist = false;
612
							// Check if the process is still in the returned process list
613
							for (int i = 0; i < pids.length; i++) {
614
								if (pids[i] == pid_tmp) {
615
									exist = true;
616
								}
617
							}
618
							if (!exist) {
619
								_processList.remove(pidstr_tmp);
620
							}
621
						} catch (Exception e) {
622
						}
623
					}
624
625
					// Populate the process list
626
					for (int i = 0; i < pids.length; i++) {
627
						if (!_processList.containsKey(new Long(pids[i]))) { // Only
628
							// create
629
							// new
630
							// process
631
							// if
632
							// not
633
							// already
634
							// exist
635
							Process p = ProcessFactory.createProcess(node, pids[i]);
636
							p.setActive(true);
637
							_processList.put(new Long(pids[i]), p);
638
						}
639
					}
640
				}
641
642
				synchronized (_processListLock) {
643
					_processListLock.notifyAll();
644
				}
645
				break;
646
			}
647
			case (int) Constants.RA_AGENT_LIST: {
648
				ActiveAgentListCommand aalCmd = (ActiveAgentListCommand) (command);
649
650
				String[] agentNames = aalCmd.getAgents();
651
				String processName = aalCmd.getProcessName();
652
				long processId = aalCmd.getProcessId();
653
654
				Process p = (Process) _processList.get(new Long(processId));
655
				p.setName(processName);
656
657
				if (agentNames != null) {
658
					for (int i = 0; i < agentNames.length; i++) {
659
						Agent newAgent = AgentFactory.createAgent(p, agentNames[i]);
660
						newAgent.setActive(true);
661
					}
662
				}
663
664
				synchronized (_agentListLock) {
665
					_agentListLock.notifyAll();
666
				}
667
				break;
668
			}
669
			case (int) Constants.RA_AGENT_DETAILS: {
670
				AgentDetailsCommand adCmd = (AgentDetailsCommand) command;
671
672
				long processId = adCmd.getProcessId();
673
				String processUUID = adCmd.getProcessUUID();
674
				String agentName = adCmd.getAgentName();
675
				String agentType = adCmd.getAgentType();
676
				String agentUUID = adCmd.getAgentUUID();
677
678
				Process p = (Process) _processList.get(new Long(processId));
679
680
				if (p != null) {
681
					p.setUUID(processUUID);
682
					Agent ag = p.getAgent(agentName);
683
					if (ag != null) {
684
						ag.setType(agentType);
685
						ag.setUUID(agentUUID);
686
						ag.addAgentListener((ProcessImpl) p);
687
					}
688
				}
689
690
				synchronized (_agentDetailsLock) {
691
					_agentDetailsLock.notifyAll();
692
				}
693
				break;
694
			}
695
			case (int) Constants.RA_PROCESS_LAUNCHED:
696
			case (int) Constants.RA_PROCESS_EXITED:
697
			case (int) Constants.RA_AGENT_ACTIVE:
698
			case (int) Constants.RA_AGENT_INACTIVE:
699
			case (int) Constants.RA_ERROR_STRING:
700
			case (int) Constants.RA_CONSOLE_INFO:
701
			case (int) Constants.RA_CUSTOM_COMMAND:
702
			case (int) Constants.RA_BINARY_CUSTOM_COMMAND:
703
			case (int) Constants.RA_SET_NAME_VALUE_PAIR: {
704
				SimpleProcessCommand cmd = (SimpleProcessCommand) command;
705
				long pid = cmd.getProcessId();
706
707
				Process p = (Process) _processList.get(new Long(pid));
708
				if ((p != null) && (p instanceof ProcessImpl)) {
709
					((ProcessImpl) p).handleCommand(command);
710
				}
711
712
				// Remote process if exited
713
				if (tag == Constants.RA_PROCESS_EXITED) {
714
					_processList.remove(new Long(pid));
715
				}
716
717
				break;
718
			}
719
			case (int) Constants.RA_PROPERTY_LIST: {
720
				PropertyListCommand qs = (PropertyListCommand) command;
721
				props = qs.getPropertyListValues();
722
				synchronized (_propertyListLock) {
723
					_propertyListLock.notify();
724
				}
725
				break;
726
			}
727
			case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR:
728
			case (int) Constants.RA_CONTROLLER_REQUEST_MONITOR_PORT: {
729
				MonitorPeerRequestCommand cmd = (MonitorPeerRequestCommand) command;
730
				long pid = cmd.getProcessId();
731
732
				Process p = (Process) _processList.get(new Long(pid));
733
				if (p != null) {
734
					try {
735
						((ProcessImpl) p).handleCommand(command);
736
					} catch (ClassCastException e) {
737
						// TODO: Error casting Process
738
					}
739
				}
740
				break;
741
			}
742
			default: {
743
			}
744
			}
745
		}
746
	}
747
748
	/**
749
	 * Proess Listener
750
	 * 
751
	 * @author samwai
752
	 * 
753
	 */
754
	class InnerProcessListener implements ProcessListener {
755
		public synchronized void processLaunched(Process process) {
756
			try {
757
				Long key = new Long(process.getProcessId());
758
				if (!_processList.containsKey(key)) {
759
					_processList.put(key, process);
760
				}
761
			} catch (InactiveProcessException e) {
762
				/* We can ignore this */
763
			}
764
		}
765
766
		public synchronized void processExited(Process process) {
767
			try {
768
				Long key = new Long(process.getProcessId());
769
				_processList.remove(key);
770
			} catch (InactiveProcessException e) {
771
				/* We can ignore this */
772
			}
773
		}
774
	}
775
776
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/DetailedProcessCommand.java (+68 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DetailedProcessCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
/**
16
 * Insert the type's description here. Creation date: (11/29/00 11:56:45 AM)
17
 * 
18
 * @author:
19
 */
20
public class DetailedProcessCommand extends SimpleProcessCommand {
21
22
	protected RAString _processUUID = new RAString("");
23
24
	/**
25
	 * DetailedProcessCommand constructor comment.
26
	 */
27
	public DetailedProcessCommand() {
28
		super();
29
	}
30
31
	/**
32
	 * Insert the method's description here. Creation date: (11/29/00 11:57:19
33
	 * AM)
34
	 * 
35
	 * @return java.lang.String
36
	 */
37
	public String getProcessUUID() {
38
		if (_processUUID != null) {
39
			return _processUUID.getData();
40
		}
41
		return null;
42
	}
43
44
	/**
45
	 * getSize method comment.
46
	 */
47
	public int getSize() {
48
		return super.getSize() + _processUUID.getSize();
49
	}
50
51
	/**
52
	 * readFromBuffer method comment.
53
	 */
54
	public int readFromBuffer(byte[] buffer, int offset) {
55
		int current = super.readFromBuffer(buffer, offset);
56
		current = Message.readRAStringFromBuffer(buffer, current, _processUUID);
57
		return current;
58
	}
59
60
	/**
61
	 * writeToBuffer method comment.
62
	 */
63
	public int writeToBuffer(byte[] buffer, int offset) {
64
		int current = super.writeToBuffer(buffer, offset);
65
		current = Message.writeRAStringToBuffer(buffer, current, _processUUID);
66
		return current;
67
	}
68
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/SimpleProcessCommand.java (+80 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SimpleProcessCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public abstract class SimpleProcessCommand extends CommandElement implements Constants {
16
	private long _processId;
17
18
	/**
19
	 * SimpleProcessCommand constructor comment.
20
	 */
21
	public SimpleProcessCommand() {
22
		super();
23
	}
24
25
	/**
26
	 * Insert the method's description here. Creation date: (9/11/00 10:32:18 PM)
27
	 * 
28
	 * @return long
29
	 */
30
	public long getProcessId() {
31
		return _processId;
32
	}
33
34
	/**
35
	 * getSize method comment.
36
	 */
37
	public int getSize() {
38
		int size = super.getSize();
39
40
		size += sizeofLong;
41
42
		return size;
43
	}
44
45
	/**
46
	 * readFromBuffer method comment.
47
	 */
48
	public int readFromBuffer(byte[] buffer, int offset) {
49
		int current = offset;
50
51
		current = super.readFromBuffer(buffer, current);
52
53
		_processId = Message.readRALongFromBuffer(buffer, current);
54
		current += sizeofLong;
55
56
		return current;
57
	}
58
59
	/**
60
	 * Insert the method's description here. Creation date: (9/11/00 10:32:18 PM)
61
	 * 
62
	 * @param new_pid
63
	 *            long
64
	 */
65
	public void setProcessId(long pid) {
66
		_processId = pid;
67
	}
68
69
	/**
70
	 * writeToBuffer method comment.
71
	 */
72
	public int writeToBuffer(byte[] buffer, int offset) {
73
		int current = offset;
74
75
		current = super.writeToBuffer(buffer, current);
76
		current = Message.writeRALongToBuffer(buffer, current, _processId);
77
78
		return current;
79
	}
80
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/Options.java (+132 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Options.java,v 1.6 2006/10/30 18:25:49 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public interface Options {
16
17
	/* Option Strings */
18
	public final static String OPTION_MONITOR_MODE = "MONITOR_MODE";
19
	public final static String OPTION_CLASS_LOAD_DETAILS = "CLASS_LOAD_DETAILS";
20
	public final static String OPTION_COLLATION_VALUES = "COLLATION_VALUES";
21
	public final static String OPTION_CONTEXT_FLOW = "CONTEXT_FLOW";
22
	public final static String OPTION_EXCEPTION_TRACING = "EXCEPTION_TRACING";
23
	public final static String OPTION_FILTERS = "FILTERS";
24
	public final static String OPTION_GC = "GC";
25
	public final static String OPTION_ID_STYLE = "ID_STYLE";
26
	public final static String OPTION_METHOD_COUNTS = "METHOD_COUNTS";
27
	public final static String OPTION_OBJ_ALLOC_IS_ARRAY = "OBJ_ALLOC_IS_ARRAY";
28
	public final static String OPTION_OPTIONS = "OPTIONS";
29
	public final static String OPTION_TICKET = "TICKET";
30
	public final static String OPTION_TIMESTAMPS = "TIMESTAMPS";
31
	public final static String OPTION_TRACE_IDREFS = "TRACE_IDREFS";
32
	public final static String OPTION_UNREFERENCED_SYMBOLS = "UNREFERENCED_SYMBOLS";
33
	public final static String OPTION_STACK_INFORMATION = "STACK_INFORMATION";
34
	public final static String OPTION_OBJ_REF_MODE = "OBJ_REF_MODE";
35
	/* V5 additions */
36
	public final static String OPTION_TRACE_MODE = "TRACE_MODE";
37
	public final static String OPTION_TRACE_START_MODE = "TRACE_START_MODE";
38
	public final static String OPTION_BURST_MODE = "BURST_MODE";
39
	public final static String OPTION_BOUNDARY_DEPTH = "BOUNDARY_DEPTH";
40
	public static final String OPTION_BURST_INVOCATIONS = "BURST_INVOCATIONS";
41
	public static final String OPTION_BURST_SECONDS = "BURST_SECONDS";
42
	public static final String OPTION_ALLOCATION_INFORMATION = "ALLOCATION_INFORMATION";
43
44
	public static final String OPTION_COMPRESS = "COMPRESS";
45
46
	public final static String OPTION_CPU_TIME = "CPU_TIME";
47
	/* Option Values */
48
	public static final String OPTION_VALUE_FULL = "full";
49
	public static final String OPTION_VALUE_ALL = "all";
50
	public static final String OPTION_VALUE_TRUE = "true";
51
	public static final String OPTION_VALUE_FALSE = "false";
52
	public static final String OPTION_VALUE_STATIC = "static";
53
	public static final String OPTION_VALUE_RELOCATABLE = "relocatable";
54
	public static final String OPTION_VALUE_STATICANDRELOCATABLE = "staticAndRelocatable";
55
	public static final String OPTION_VALUE_DEFAULT = "default";
56
	public static final String OPTION_VALUE_NONE = "none";
57
	public static final String OPTION_VALUE_DELETES = "deletes";
58
	public static final String OPTION_VALUE_DELETESANDMOVES = "deletesAndMoves";
59
	public static final String OPTION_VALUE_NORMAL = "normal";
60
	public static final String OPTION_VALUE_BOUNDARY = "boundary";
61
	public static final String OPTION_VALUE_CONTIGUOUS = "contiguous";
62
	public static final String OPTION_VALUE_BOUNDARYANDCONTIGUOUS = "boundaryAndContiguous";
63
	public static final String OPTION_VALUE_RESPECT_FILTER = "respectFilter";
64
	public static final String OPTION_VALUE_FILTER_OWNER = "filterOwner";
65
	public static final String OPTION_VALUE_IGNORE_FILTER = "ignoreFilter";
66
	/* V5 Additions */
67
	public final static String OPTION_VALUE_NOOBJECTCORRELATION = "noObjectCorrelation";
68
	public static final String OPTION_VALUE_FILTER = "filter";
69
	public static final String OPTION_VALUE_TRIGGERSINGLETHREADED = "triggerSingleThreaded";
70
	public static final String OPTION_VALUE_TRIGGERMULTITHREADED = "triggerMultiThreaded";
71
	public static final String OPTION_VALUE_INVOCATIONS = "invocations";
72
	public static final String OPTION_VALUE_SECONDS = "seconds";
73
	public static final String OPTION_VALUE_SECONDSANDINVOCATIONS = "secondsAndInvocations";
74
75
	public static final String OPTION_VALUE_AGGREGATE = "aggregate";
76
77
	/*
78
	 * This option must be in place if the user has selected execution flow without instance level information.
79
	 */
80
	public final static String[][] OPTIONS_EXECUTION_FLOW = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_STACK_INFORMATION, OPTION_VALUE_NORMAL }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
81
82
	/*
83
	 * This option must be in place if the user has selected execution flow with instance level information.
84
	 */
85
	public final static String[][] OPTIONS_EXECUTION_FLOW_INSTANCES = { { OPTION_TRACE_MODE, OPTION_VALUE_FULL }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_DEFAULT }, { OPTION_STACK_INFORMATION, OPTION_VALUE_NORMAL }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
86
87
	/*
88
	 * This option must be used if the user has selected execution flow and some boundary information, but no instance level information.
89
	 */
90
	public final static String[][] OPTIONS_EXECUTION_FLOW_BOUNDARY = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_STACK_INFORMATION, OPTION_VALUE_BOUNDARY }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
91
92
	/*
93
	 * This option must be used if the user has selected execution flow and some boundary information, as well as instance level information.
94
	 */
95
	public final static String[][] OPTIONS_EXECUTION_FLOW_BOUNDARY_INSTANCES = { { OPTION_TRACE_MODE, OPTION_VALUE_FULL }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_DEFAULT }, { OPTION_STACK_INFORMATION, OPTION_VALUE_BOUNDARY }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
96
97
	/*
98
	 * This option must be in place if the user has selected that they do not want any execution behaviour at all.
99
	 */
100
	public final static String[][] OPTIONS_EXECUTION_FLOW_NONE = { { OPTION_STACK_INFORMATION, OPTION_VALUE_NONE }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
101
102
	/* This option must be in place if the user has selected to collect cpu time events */
103
	public final static String[][] OPTIONS_COLLECT_CPU_TIME = { { OPTION_CPU_TIME, OPTION_VALUE_TRUE }, };
104
105
	/*
106
	 * This option must be in place if the user does not want object correlation information.
107
	 */
108
	public final static String[][] OPTIONS_NO_INSTANCE_INFORMATION = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_NONE } };
109
110
	public final static String[][] OPTIONS_ANALYZE_HEAP = { { OPTION_TRACE_MODE, OPTION_VALUE_FULL }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_DEFAULT }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
111
112
	public final static String[][] OPTIONS_ANALYZE_HEAP_NONE = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_NONE } };
113
114
	/*
115
	 * This option must be in place if the user has selected Method Coverage but not EXECUTION_FLOW
116
	 */
117
	public final static String[][] OPTIONS_COVERAGE_NO_FLOW = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_STACK_INFORMATION, OPTION_VALUE_NORMAL }, { OPTION_METHOD_COUNTS, OPTION_VALUE_TRUE }, { OPTION_UNREFERENCED_SYMBOLS, OPTION_VALUE_TRUE } };
118
119
	/*
120
	 * This option must be in place if the user has selected method coverage.
121
	 */
122
	public final static String[][] OPTIONS_COVERAGE = { { OPTION_TRACE_MODE, OPTION_VALUE_NOOBJECTCORRELATION }, { OPTION_METHOD_COUNTS, OPTION_VALUE_TRUE }, { OPTION_UNREFERENCED_SYMBOLS, OPTION_VALUE_TRUE } };
123
124
	/* This option must be in place if the user has selected to observe threading events */
125
126
	public final static String[][] OPTIONS_THREAD_EVENTS = { { OPTION_MONITOR_MODE, OPTION_VALUE_ALL } };
127
128
	/*
129
	 * These are the default options, when nothing is selected. Nothing should be collected. These defaults are overridden once the options are set with values of higher precedence.
130
	 */
131
	public final static String[][] OPTIONS_DEFAULT = { { OPTION_TRACE_MODE, OPTION_VALUE_NONE }, { OPTION_ALLOCATION_INFORMATION, OPTION_VALUE_NONE }, { OPTION_STACK_INFORMATION, OPTION_VALUE_NONE }, { OPTION_TICKET, OPTION_VALUE_TRUE } };
132
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/PeerUnreachableCommand.java (+20 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: PeerUnreachableCommand.java,v 1.1 2006/03/06 19:49:40 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class PeerUnreachableCommand extends MonitorPeerRequestCommand {
15
16
	public PeerUnreachableCommand() {
17
		super();
18
		_tag = RA_PEER_UNREACHABLE;
19
	}
20
}
(-)src-local-public/org/eclipse/hyades/execution/security/User.java (+112 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: User.java,v 1.5 2006/03/20 14:07:51 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import java.io.IOException;
16
import java.security.Principal;
17
18
import org.eclipse.hyades.execution.core.util.Noop;
19
import org.eclipse.hyades.execution.local.common.AuthenticateCommand;
20
import org.eclipse.hyades.execution.local.common.CommandElement;
21
import org.eclipse.hyades.execution.local.common.Constants;
22
import org.eclipse.hyades.execution.local.common.ControlMessage;
23
import org.eclipse.hyades.execution.local.control.Application;
24
import org.eclipse.hyades.execution.local.control.CommandHandler;
25
import org.eclipse.hyades.execution.local.control.Connection;
26
import org.eclipse.hyades.execution.local.control.Node;
27
28
public class User implements Principal, CommandHandler {
29
30
	private String _name;
31
	private String _password;
32
	private Application _app;
33
	private String _alias;
34
	private boolean _isPasswordEncrypted;
35
36
	{
37
		Noop.sink(this._alias, this._isPasswordEncrypted);
38
	}
39
40
	public static final boolean ENABLE_PASSWORD_ENCRYPTION = false;
41
42
	public User(Application app, String name, String password) {
43
		_app = app;
44
		_name = name;
45
		setPassword(password);
46
	}
47
48
	/**
49
	 * @see java.security.Principal#getName()
50
	 */
51
	public String getName() {
52
		return _name;
53
	}
54
55
	public void setPassword(String password) {
56
		/*
57
		 * Try and store the passowrd in memory encrypted. If we fail to encrypt
58
		 * the password we will store it as is.
59
		 */
60
		try {
61
			if (ENABLE_PASSWORD_ENCRYPTION) {
62
				// _password=com.ibm.ISecurityUtilityImpl.PasswordUtil.encode(password);
63
				_isPasswordEncrypted = true;
64
			} else {
65
				throw new RuntimeException();
66
			}
67
		} catch (Exception e) {
68
			_password = password;
69
			_isPasswordEncrypted = false;
70
		}
71
72
	}
73
74
	public Application getApplication() {
75
		return _app;
76
	}
77
78
	public void login(Connection connection) throws IOException {
79
		login(connection, this);
80
	}
81
82
	public void login(Connection connection, CommandHandler handler) throws IOException {
83
84
		ControlMessage message = new ControlMessage();
85
		AuthenticateCommand command = null;
86
		;
87
88
		String decryptedPassword = null;
89
		try {
90
91
			if (ENABLE_PASSWORD_ENCRYPTION) {
92
				// decryptedPassword=com.ibm.ISecurityUtilityImpl.PasswordUtil.decode(_password);
93
			} else {
94
				throw new RuntimeException();
95
			}
96
		} catch (Exception e) {
97
			decryptedPassword = _password;
98
		}
99
		command = new AuthenticateCommand(_name, decryptedPassword);
100
		message.appendCommand(command);
101
		connection.sendMessage(message, handler);
102
	}
103
104
	public void incommingCommand(Node node, CommandElement command) {
105
		switch ((int) command.getTag()) {
106
		case (int) Constants.RA_AUTHENTICATION_SUCCESSFUL:
107
			break;
108
		case (int) Constants.RA_AUTHENTICATION_FAILED:
109
			break;
110
		}
111
	}
112
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Application.java (+19 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Application.java,v 1.2 2005/02/25 22:17:10 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.security.Principal;
16
17
public interface Application extends Principal {
18
19
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/RABinaryArray.java (+72 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: RABinaryArray.java,v 1.3 2005/04/05 15:48:58 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class RABinaryArray implements Constants {
16
17
	protected byte[] _data;
18
	protected int _padding = 0;
19
20
	public RABinaryArray() {
21
		super();
22
	}
23
24
	public RABinaryArray(byte[] data) {
25
		if (data != null) {
26
			_data = data;
27
			calculatePadding();
28
		} else {
29
			_padding = 0;
30
		}
31
	}
32
33
	private void calculatePadding() {
34
		_padding = 4 - _data.length % 4;
35
		if (_padding == 4) {
36
			_padding = 0;
37
		}
38
	}
39
40
	public byte[] getData() {
41
		return _data;
42
	}
43
44
	public int getPadding() {
45
		return _padding;
46
	}
47
48
	public int getSize() {
49
		return sizeofLong + _data.length + _padding;
50
	}
51
52
	public long length() {
53
		if (_data != null)
54
			return _data.length;
55
56
		return 0;
57
	}
58
59
	public void setData(byte[] data) {
60
		_data = data;
61
		calculatePadding();
62
	}
63
64
	public void setData(byte[] data, int offset, int length) {
65
		if (data != null) {
66
			_data = new byte[length];
67
			System.arraycopy(data, offset, _data, 0, length);
68
			calculatePadding();
69
		}
70
	}
71
72
}
(-)src-local-public/org/eclipse/hyades/execution/security/SecureConnectionRequiredException.java (+39 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SecureConnectionRequiredException.java,v 1.4 2005/09/13 16:46:21 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.security;
14
15
import org.eclipse.hyades.execution.local.common.ServerSecurityInfoCommand;
16
import org.eclipse.hyades.execution.local.control.AgentControllerUnavailableException;
17
18
public class SecureConnectionRequiredException extends AgentControllerUnavailableException {
19
20
	private static final long serialVersionUID = 3977858458274181938L;
21
	ServerSecurityInfoCommand _details;
22
23
	public SecureConnectionRequiredException(ServerSecurityInfoCommand command) {
24
		_details = command;
25
	}
26
27
	public boolean isPasswordProtected() {
28
		return _details.isPasswordProtected();
29
	}
30
31
	public boolean isClientAuthenticationRequired() {
32
		return _details.isClientAuthenticationRequired();
33
	}
34
35
	public long getSecurePort() {
36
		return _details.getSecurePort();
37
	}
38
39
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/RAString.java (+111 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: RAString.java,v 1.4 2005/11/04 19:06:30 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class RAString implements Constants {
16
	protected String _data = "";
17
	protected int _padding = 0;
18
19
	/**
20
	 * RAString constructor comment.
21
	 */
22
	public RAString() {
23
		super();
24
	}
25
26
	/**
27
	 * Insert the method's description here. Creation date: (10/31/00 8:07:25 PM)
28
	 * 
29
	 * @param data
30
	 *            java.lang.String
31
	 */
32
	public RAString(String data) {
33
		setData(data);
34
	}
35
36
	/**
37
	 * Insert the method's description here. Creation date: (11/2/00 10:18:58 PM)
38
	 */
39
	private void calculatePadding() {
40
		try {
41
			_padding = 4 - _data.getBytes("UTF-8").length % 4;
42
			if (_padding == 4) {
43
				_padding = 0;
44
			}
45
		} catch (Exception e) {
46
			_padding = 4 - _data.length() % 4;
47
			if (_padding == 4) {
48
				_padding = 0;
49
			}
50
		}
51
	}
52
53
	/**
54
	 * Insert the method's description here. Creation date: (10/31/00 8:08:17 PM)
55
	 * 
56
	 * @return java.lang.String
57
	 */
58
	public String getData() {
59
		return _data;
60
	}
61
62
	/**
63
	 * Insert the method's description here. Creation date: (10/31/00 8:08:30 PM)
64
	 * 
65
	 * @return int
66
	 */
67
	public int getPadding() {
68
		return _padding;
69
	}
70
71
	/**
72
	 * Insert the method's description here. Creation date: (10/31/00 8:12:24 PM)
73
	 * 
74
	 * @return long
75
	 */
76
	public int getSize() {
77
		try {
78
			return sizeofLong + _data.getBytes("UTF-8").length + _padding;
79
		} catch (Throwable e) {
80
			return sizeofLong + _data.length() + _padding;
81
		}
82
	}
83
84
	/**
85
	 * Insert the method's description here. Creation date: (10/31/00 8:09:17 PM)
86
	 * 
87
	 * @return long
88
	 */
89
	public long length() {
90
		if (_data != null)
91
			return _data.length();
92
93
		return 0;
94
	}
95
96
	/**
97
	 * Insert the method's description here. Creation date: (11/2/00 5:17:34 PM)
98
	 * 
99
	 * @param data
100
	 *            java.lang.String
101
	 */
102
	public void setData(String data) {
103
		if (data != null) {
104
			_data = data;
105
			calculatePadding();
106
		} else {
107
			_data = "";
108
			_padding = 0;
109
		}
110
	}
111
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/DataServerListener.java (+24 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DataServerListener.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
/**
16
 * This interface is used in conjunction with the TCPDataServer to notify
17
 * implementors when the TCPDataProcessor has completed doing all of its work
18
 * and the processor is exiting.
19
 */
20
public interface DataServerListener extends DataProcessor {
21
22
	void dataServerExited();
23
24
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/GetPropertyListCommand.java (+81 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: GetPropertyListCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class GetPropertyListCommand extends CommandElement implements Constants {
16
	private RAString name = null;
17
	private RAString type = null;
18
	private RAString agentUUID = new RAString("");
19
20
	public GetPropertyListCommand() {
21
		super();
22
		_tag = RA_GET_PROPERTY_LIST;
23
	}
24
25
	public void setName(String str) {
26
		name = new RAString(str);
27
	}
28
29
	public RAString getName() {
30
		return name;
31
	}
32
33
	public void setType(String str) {
34
		type = new RAString(str);
35
	}
36
37
	public RAString getType() {
38
		return type;
39
	}
40
41
	public void setAgentUUID(String str) {
42
		agentUUID = new RAString(str);
43
	}
44
45
	public RAString getAgentUUID() {
46
		return agentUUID;
47
	}
48
49
	public int readFromBuffer(byte[] buffer, int offset) {
50
		int current = offset;
51
52
		current = super.readFromBuffer(buffer, current);
53
		current = Message.readRAStringFromBuffer(buffer, current, name);
54
		current = Message.readRAStringFromBuffer(buffer, current, type);
55
		current = Message.readRAStringFromBuffer(buffer, current, agentUUID);
56
57
		return current;
58
	}
59
60
	public int writeToBuffer(byte[] buffer, int offset) {
61
		int current = offset;
62
63
		current = super.writeToBuffer(buffer, current);
64
		current = Message.writeRAStringToBuffer(buffer, current, name);
65
		current = Message.writeRAStringToBuffer(buffer, current, type);
66
		current = Message.writeRAStringToBuffer(buffer, current, agentUUID);
67
68
		return current;
69
	}
70
71
	public int getSize() {
72
		int size = super.getSize();
73
74
		size += name.getSize();
75
		size += type.getSize();
76
		size += agentUUID.getSize();
77
78
		return size;
79
	}
80
81
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ResourceLocation.java (+70 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ResourceLocation.java,v 1.5 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class ResourceLocation extends CommandElement implements Constants {
15
	private long _port;
16
	private RAString _jobKey = new RAString("");
17
18
	public ResourceLocation() {
19
		super();
20
		_tag = RA_RESOURCE_LOCATION;
21
	}
22
23
	public int getPort() {
24
		return (int) _port;
25
	}
26
27
	public void setPort(int port) {
28
		_port = port;
29
	}
30
31
	public String getJobKey() {
32
		return _jobKey.getData();
33
	}
34
35
	public void setJobKey(String key) {
36
		_jobKey = new RAString(key);
37
	}
38
39
	public int getSize() {
40
		int size = super.getSize();
41
42
		size += sizeofLong; // port
43
		size += _jobKey.getSize();
44
45
		return size;
46
	}
47
48
	public int readFromBuffer(byte[] buffer, int offset) {
49
		int current = offset;
50
51
		current = super.readFromBuffer(buffer, current);
52
53
		_port = Message.readRALongFromBuffer(buffer, current);
54
		current += sizeofLong;
55
56
		current = Message.readRAStringFromBuffer(buffer, current, _jobKey);
57
58
		return current;
59
	}
60
61
	public int writeToBuffer(byte[] buffer, int offset) {
62
		int current = offset;
63
64
		current = super.writeToBuffer(buffer, current);
65
		current = Message.writeRALongToBuffer(buffer, current, _port);
66
		current = Message.writeRAStringToBuffer(buffer, current, _jobKey);
67
68
		return current;
69
	}
70
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ConnectionImpl.java (+556 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ConnectionImpl.java,v 1.10 2006/05/13 02:02:53 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InterruptedIOException;
18
import java.io.OutputStream;
19
import java.net.InetAddress;
20
import java.net.Socket;
21
import java.net.SocketException;
22
import java.util.Enumeration;
23
import java.util.Vector;
24
25
import org.eclipse.hyades.execution.local.common.CommandElement;
26
import org.eclipse.hyades.execution.local.common.Constants;
27
import org.eclipse.hyades.execution.local.common.ControlMessage;
28
import org.eclipse.hyades.execution.local.common.Message;
29
import org.eclipse.hyades.execution.local.common.ServerSecurityInfoCommand;
30
import org.eclipse.hyades.execution.security.AuthenticationListener;
31
import org.eclipse.hyades.execution.security.LoginFailedException;
32
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
33
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
34
35
public class ConnectionImpl implements Connection {
36
37
	protected Socket _socket;
38
39
	protected Node _node;
40
41
	protected int _port;
42
43
	private static long _context = 1;
44
45
	private ContextMapper _contextMapper = null;
46
47
	private CommandHandler _cmdHandler = null;
48
49
	private boolean _isComplete = false;
50
51
	private final Vector _listeners = new Vector();
52
53
	// private final Vector _authenticationlisteners = new Vector();
54
55
	private final Object _connectionLock = new Object();
56
57
	private static final Object contextLock = new Object();
58
59
	private boolean _isInitialized = false;
60
61
	private SecureConnectionRequiredException _connectionException = null;
62
63
	private int _connectionTimeout = 10000; // 10 sec
64
65
	public ConnectionImpl() {
66
		super();
67
	}
68
69
	public void connect(Node node, int port) throws IOException, LoginFailedException, SecureConnectionRequiredException, UntrustedAgentControllerException {
70
		_port = port;
71
		int offset = 0;
72
		InetAddress[] addrs = node.getAllInetAddresses();
73
74
		do {
75
			/* Connect to the remote machine */
76
			try {
77
				_socket = new Socket(addrs[offset], port);
78
				break;
79
			} catch (IOException e) {
80
				offset++;
81
				if (offset == addrs.length) {
82
					throw e;
83
				}
84
			}
85
		} while (offset < addrs.length);
86
87
		_node = node;
88
		this.init();
89
	}
90
91
	/* Init */
92
	protected void init() throws IOException, SecureConnectionRequiredException {
93
94
		/* Set the timeout on the socket reader to be 1 second */
95
		try {
96
			_socket.setSoTimeout(1000);
97
			_socket.setTcpNoDelay(true);
98
		} catch (SocketException e) {
99
			/* We can ignore this */
100
		}
101
102
		_connectionException = null;
103
		_contextMapper = new ContextMapper();
104
		_cmdHandler = new CommandHandler() {
105
			public void incommingCommand(Node node, CommandElement command) {
106
				long contextId = command.getContext();
107
108
				/* Intercept authentication requests */
109
				switch ((int) command.getTag()) {
110
					case (int) Constants.RA_SERVER_SECURITY_REQUIREMENTS:
111
						_connectionException = new SecureConnectionRequiredException((ServerSecurityInfoCommand) command);
112
						synchronized(_connectionLock) {
113
							_connectionLock.notifyAll();
114
						}
115
						disconnect();
116
						break;
117
					default:
118
						synchronized(_connectionLock) {
119
							_connectionLock.notifyAll();
120
						}
121
122
						/*
123
						 * Find the command handler associated with this contextId
124
						 * and forward the message appropriately.
125
						 */
126
						CommandHandler ch = _contextMapper.getHandler(contextId);
127
						if (ch != null) {
128
							ch.incommingCommand(_node, command);
129
						} else {
130
							_node.incommingCommand(_node, command);
131
						}
132
				}
133
			}
134
		};
135
136
		/*
137
		 * RKD: With the V5 Agent Controller it first accepts the socket
138
		 * connection and then determines is the connection is allowed. If the
139
		 * connection is not allowed the the connection is cut. We need to first
140
		 * connect and then determine if we have been cut off. The connection
141
		 * has already occurred above us in the stack. We then will wait until
142
		 * either a read timeout has occured on the reader thread or the
143
		 * connection gets cut by the other side.
144
		 */
145
146
		SocketReaderThread reader = new SocketReaderThread();
147
		if (_node.getUser() == null) {
148
			reader.setName(_node.getName() + "_connection");
149
		} else {
150
			reader.setName(_node.getName() + "_" + _node.getUser().getName() + "_connection");
151
		}
152
		reader.setDaemon(true);
153
		reader.start();
154
155
		_isInitialized = true;
156
157
		/*
158
		 * If this connection has a pending exception because the server is
159
		 * secure we need to throw the exception so that the caller can
160
		 * create a new connection with the proper security settings.
161
		 */
162
		synchronized (_connectionLock) {
163
			try {
164
				_connectionLock.wait(_connectionTimeout);
165
			} catch (InterruptedException e) {
166
				e.printStackTrace();
167
			}
168
169
			if (_connectionException != null) {
170
				throw _connectionException;
171
			}
172
		}
173
	}
174
175
	public void sendMessage(ControlMessage msg, CommandHandler handler) throws IOException {
176
177
		int count = msg.getSize();
178
		byte[] buffer = new byte[count];
179
180
		int commandCount = msg.getCommandCount();
181
182
		/*
183
		 * Need to store the context for rerouting on return, lock is acquired
184
		 * so context static variable can be incremented safely, synchronized
185
		 * surrounds loop instead of inside loop to minimize acquisition of
186
		 * locks within loop.
187
		 * 
188
		 * The part of the loop that did not deal with incrementing and storing
189
		 * the context has been extracted out into another loop as to minimize
190
		 * time of lock.
191
		 */
192
		synchronized (ConnectionImpl.contextLock) {
193
			for (int i = 0; i < commandCount; i++) {
194
				msg.getCommand(i).setContext(ConnectionImpl._context++);
195
			}
196
		}
197
198
		/*
199
		 * The command count loop is repeated outside of the synchronized block
200
		 * to minimize duration of the context lock.
201
		 */
202
		for (int i = 0; i < commandCount; i++) {
203
			this._contextMapper.addContext(msg.getCommand(i).getContext(), handler);
204
		}
205
206
		msg.writeToBuffer(buffer, 0);
207
208
		OutputStream stream = _socket.getOutputStream();
209
		stream.write(buffer);
210
		stream.flush();
211
212
	}
213
214
	public void disconnect() {
215
		synchronized (_connectionLock) {
216
			if (!_isComplete) {
217
				_isComplete = true;
218
				_connectionLock.notifyAll();
219
				try {
220
					_socket.close();
221
				} catch (IOException e) {
222
					/* We can ignore this */
223
				}
224
225
				/*
226
				 * If this is a nodeimpl clear the keystore spec so it tries an
227
				 * insecure connect next time
228
				 * 
229
				 * NOTE: Commented out since this might be overwriting the security
230
				 * parameter when the secured control channel and secured file
231
				 * server both access the same NodeImpl. This is when the insecured
232
				 * connection is disconnecting. Please see TPTP bug 136426.
233
				 */
234
//				if (_node instanceof NodeImpl) {
235
//					((NodeImpl) _node).setSecurityParameters(null); // Bug 136426
236
//				}
237
238
				/* Inform each of the listeners that the connection is closed. */
239
				synchronized (_listeners) {
240
					Enumeration e = _listeners.elements();
241
					while (e.hasMoreElements()) {
242
						ConnectionListener listener = (ConnectionListener) e.nextElement();
243
						listener.connectionClosed(this);
244
					}
245
				}
246
			}
247
		}
248
	}
249
250
	public Node getNode() {
251
		return _node;
252
	}
253
254
	public boolean isActive() {
255
		if (_isInitialized) {
256
			return !_isComplete;
257
		}
258
		return false;
259
	}
260
261
	public int getPort() {
262
		return _port;
263
	}
264
265
	/**
266
	 * @see Connection#addConnectionListener(ConnectionListener)
267
	 */
268
	public void addConnectionListener(ConnectionListener listener) {
269
		synchronized (_listeners) {
270
			if (!_listeners.contains(listener)) {
271
				_listeners.add(listener);
272
			}
273
		}
274
	}
275
276
	/**
277
	 * @see Connection#removeConnectionListener(ConnectionListener)
278
	 */
279
	public void removeConnectionListener(ConnectionListener listener) {
280
		synchronized (_listeners) {
281
			if (_listeners.contains(listener)) {
282
				_listeners.remove(listener);
283
			}
284
		}
285
	}
286
287
	/**
288
	 * @see Connection#addAuthenticationListener(AuthenticationListener)
289
	 */
290
	public void addAuthenticationListener(AuthenticationListener listener) {
291
		// synchronized(_authenticationlisteners) {
292
		// if(!_authenticationlisteners.contains(listener)) {
293
		// _authenticationlisteners.add(listener);
294
		// }
295
		// }
296
297
	}
298
299
	/**
300
	 * @see Connection#removeAuthenticationListener(AuthenticationListener)
301
	 */
302
	public void removeAuthenticationListener(AuthenticationListener listener) {
303
		// synchronized(_authenticationlisteners) {
304
		// if(_authenticationlisteners.contains(listener)) {
305
		// _authenticationlisteners.remove(listener);
306
		// }
307
		// }
308
	}
309
310
	protected int processControlMessage(byte[] buffer, int offset, int length) {
311
		if (_cmdHandler != null) {
312
			ControlMessage msg = new ControlMessage();
313
			int current = -1;
314
			try {
315
				current = msg.readFromBuffer(buffer, offset, length);
316
317
				/* If we read more bytes then were valid, return -1 */
318
				if (current > offset + length) {
319
					return -1;
320
				}
321
			} catch (IndexOutOfBoundsException e) { /*
322
			 * 185463 changed to
323
			 * superclass because both
324
			 * String and Array
325
			 * IndexOutOfBoundsExceptions
326
			 * can be thrown
327
			 */
328
				/*
329
				 * We have reached the end of the buffer so we have an
330
				 * incomplete message, return -1
331
				 */
332
				return -1;
333
			} catch (Exception e) {
334
				/*
335
				 * There was some other exception reading the message so we
336
				 * can't handle the message. return -1 to indicate an error
337
				 */
338
				return -1; /* 185463 */
339
			}
340
341
			/* If we have parsed the message successfully Then process it */
342
			if (current == msg.getLength() + offset) {
343
				/* Valid pass on each command */
344
				int count = msg.getCommandCount();
345
				for (int i = 0; i < count; i++) {
346
					_cmdHandler.incommingCommand(_node, msg.getCommand(i));
347
				}
348
			}
349
350
			return current;
351
		}
352
		return -1;
353
	}
354
355
	class SocketReaderThread extends Thread implements Constants {
356
357
		public void run() {
358
359
			/* Run forever */
360
			byte[] buffer = new byte[MAX_MESSAGE_LENGTH];
361
			int masterOffset = 0;
362
			int msgOffset = 0;
363
			boolean incompleteMsg; /* 185463 */
364
			int timeoutCount = 0;
365
366
			while (!_isComplete) {
367
				incompleteMsg = false; /* 185463 */
368
369
				try {
370
371
					/*
372
					 * Get the InputStream for this socket so we can read some
373
					 * data
374
					 */
375
					InputStream inStream = _socket.getInputStream();
376
377
					// >>> Bug 128421 begins
378
					// Workaround to avoid JVM inconsistency of implementation
379
					// of InputStream.read()
380
					// In some JSSE implementation the read(buf, off, 0) blocks
381
					int bytesRead;
382
					int len = buffer.length - masterOffset;
383
					if (len == 0) {
384
						bytesRead = 0; // Avoid reading from input stream if
385
						// there is nothing to read
386
					} else {
387
						bytesRead = inStream.read(buffer, masterOffset, len);
388
					}
389
					// int bytesRead=inStream.read(buffer, masterOffset,
390
					// buffer.length-masterOffset);
391
					// <<< Bug 128421 ends
392
393
					if (bytesRead == -1) {
394
						break;
395
					}
396
397
					/* Is this a valid message type */
398
					Message incommingMessage = new Message();
399
400
					while (msgOffset < (bytesRead + masterOffset)) {
401
						int newOffset = 0;
402
						/*
403
						 * First we try and read the message header information.
404
						 * It may be that we overrun our buffer or we overrun
405
						 * the number of bytes written. If either is the case,
406
						 * compress and re-read.
407
						 */
408
						try {
409
							newOffset = incommingMessage.readFromBuffer(buffer, msgOffset);
410
411
							/*
412
							 * Did we overrun the bytes written? ie do we have
413
							 * an incomplete message header? bugzilla 113831 -
414
							 * also changed the test from > to >= because if it
415
							 * they are equal then the message length is missing
416
							 * from the header so the message is incomplete.
417
							 */
418
							if (newOffset >= (masterOffset + bytesRead)) {
419
								/*
420
								 * Assumption is that we have processed other
421
								 * parts of the message so masterOffset > 0
422
								 */
423
								/*
424
								 * Compress the buffer and read the socket to
425
								 * get the remainder of the message
426
								 */
427
								if (msgOffset > 0) {
428
									masterOffset = masterOffset + bytesRead - msgOffset;
429
									for (int i = 0; i < masterOffset; i++) {
430
										buffer[i] = buffer[msgOffset + i];
431
									}
432
									msgOffset = 0;
433
								}
434
								incompleteMsg = true;
435
436
								break;
437
								/* 185463 end */
438
							}
439
						} catch (IndexOutOfBoundsException e) { /* 185463 */
440
							/*
441
							 * We overran our buffer so we have an incomplete
442
							 * message. Compress the buffer and read the socket
443
							 * to get the remainder of the message Assumption is
444
							 * that we have processed other parts of the message
445
							 * so masterOffset > 0
446
							 */
447
							if (msgOffset > 0) {
448
								masterOffset = masterOffset + bytesRead - msgOffset;
449
								for (int i = 0; i < masterOffset; i++) {
450
									buffer[i] = buffer[msgOffset + i];
451
								}
452
								msgOffset = 0;
453
							}
454
							incompleteMsg = true;
455
							break;
456
						} catch (Exception e) {
457
							/*
458
							 * Don't know what happened here so let's ignore
459
							 * this message and get the next one
460
							 */
461
							/* Should log a message here */
462
							System.out.println(e.toString());
463
							break;
464
							/* 185463 end */
465
						}
466
467
						/*
468
						 * We have the header information, now lets try and get
469
						 * the entire message. Once again the same error
470
						 * conditions can occur.
471
						 */
472
						if (incommingMessage.getType() != RA_ACKNOWLEDGEMENT_MESSAGE) {
473
							newOffset = processControlMessage(buffer, msgOffset, bytesRead + masterOffset - msgOffset);
474
							/*
475
							 * If there was an error processing the message or
476
							 * we overran the data read from the socket then we
477
							 * have an incomplete message so we have to go back
478
							 * and read the rest of the message from the socket
479
							 */
480
							if (newOffset == -1) {
481
								/*
482
								 * If we processed some of the message Then move
483
								 * the remainder of the message to the beginning
484
								 * of the buffer so we have more room to read
485
								 * from the socket
486
								 */
487
								incompleteMsg = true;
488
								if (msgOffset > 0) {
489
									masterOffset = masterOffset + bytesRead - msgOffset;
490
									for (int i = 0; i < masterOffset; i++) {
491
										buffer[i] = buffer[msgOffset + i];
492
									}
493
									msgOffset = 0;
494
								} else {
495
									// If buffer is completely filled up
496
									if ((bytesRead == 0) && (masterOffset == buffer.length)) {
497
										byte[] tmpbuffer = new byte[buffer.length * 2]; // double
498
										// the
499
										// buffer
500
										// size
501
										/*
502
										 * Copy necessary data over to new
503
										 * buffer
504
										 */
505
										System.arraycopy(buffer, 0, tmpbuffer, 0, buffer.length);
506
										buffer = tmpbuffer;
507
									}
508
									masterOffset += bytesRead;
509
								}
510
								break;
511
								/* 185463 end */
512
							}
513
514
							msgOffset = newOffset;
515
						}
516
					} /* end of inner while */
517
518
					/* 185463 begin */
519
					if (!incompleteMsg) {
520
						masterOffset = 0;
521
						msgOffset = 0;
522
					}
523
					/* 185463 end */
524
				} catch (InterruptedIOException e) {
525
					/*
526
					 * This happens as the read has timed out. Just continue as
527
					 * the socket is still valid. If we are still locked because
528
					 * we are unsure if the connection is good then we should
529
					 * make sure we allow it to continue.
530
					 */
531
					if (timeoutCount > 6 && !_isInitialized) {
532
						synchronized (_connectionLock) {
533
							_connectionLock.notifyAll();
534
						}
535
					}
536
					timeoutCount++;
537
538
				} catch (SocketException e) {
539
					/*
540
					 * this is thrown when the RAC cuts our connection because
541
					 * we must support security or if the host has been denied
542
					 * access
543
					 */
544
545
					break;
546
547
				} catch (IOException e) {
548
					break;
549
				}
550
			} /* end of outer while */
551
			/* The server is now stopping */
552
			disconnect();
553
		}
554
	}
555
556
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AttachToAgentCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AttachToAgentCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AttachToAgentCommand extends SimpleAgentInfoCommand {
16
17
	/**
18
	 * AttachToVMCommand constructor comment.
19
	 */
20
	public AttachToAgentCommand() {
21
		super();
22
		_tag = RA_ATTACH_TO_AGENT;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/StartMonitoringLocalAgentCommand.java (+49 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: StartMonitoringLocalAgentCommand.java,v 1.2 2006/02/06 17:39:31 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class StartMonitoringLocalAgentCommand extends SimpleAgentInfoCommand {
16
	private RAString _file = new RAString();
17
18
	public StartMonitoringLocalAgentCommand() {
19
		super();
20
		_tag = RA_START_MONITORING_AGENT_LOCAL;
21
	}
22
23
	public String getFile() {
24
		return _file.getData();
25
	}
26
27
	public void setFile(String file) {
28
		_file = new RAString(file);
29
	}
30
31
	public int getSize() {
32
		return super.getSize() + _file.getSize();
33
	}
34
35
	public int readFromBuffer(byte[] buffer, int offset) {
36
		int current = super.readFromBuffer(buffer, offset);
37
		current = Message.readRAStringFromBuffer(buffer, current, _file);
38
39
		return current;
40
	}
41
42
	public int writeToBuffer(byte[] buffer, int offset) {
43
		int current = super.writeToBuffer(buffer, offset);
44
		current = Message.writeRAStringToBuffer(buffer, current, _file);
45
46
		return current;
47
	}
48
49
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ShutdownCommand.java (+20 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ShutdownCommand.java,v 1.1 2006/05/03 19:36:54 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class ShutdownCommand extends CommandElement {
15
16
	public ShutdownCommand() {
17
		_tag = Constants.RA_SHUTDOWN;
18
	}
19
20
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/Console.java (+311 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Console.java,v 1.8 2006/10/30 18:25:49 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InterruptedIOException;
18
import java.net.InetAddress;
19
import java.net.ServerSocket;
20
import java.net.Socket;
21
import java.net.UnknownHostException;
22
23
import org.eclipse.hyades.execution.core.file.IFileManagerExtended;
24
import org.eclipse.hyades.execution.local.control.Node;
25
import org.eclipse.hyades.execution.local.file.FileManagerFactory;
26
27
public class Console extends Thread implements Constants {
28
29
	protected ServerSocket _sock;
30
31
	protected DataProcessor _processor;
32
33
	protected long _ip = 0;
34
35
	protected long _port = 0;
36
37
	protected Node _node;
38
39
	private boolean _started = false;
40
41
	private boolean _valid = true;
42
43
	private Socket _activeConnection;
44
45
	/**
46
	 * Console constructor comment.
47
	 */
48
	public Console() {
49
		super();
50
		/* Don't block the VM from exiting */
51
		this.setName("Console"); /* 9707 */
52
		this.setDaemon(true);
53
	}
54
55
	/**
56
	 * Construct a console that knows about the node that will try to
57
	 * communicate with it
58
	 */
59
	public Console(Node node) {
60
		this();
61
		this._node = node;
62
	}
63
64
	/**
65
	 * Console constructor comment.
66
	 * 
67
	 * @param name
68
	 *            java.lang.String
69
	 */
70
	public Console(String name) {
71
		super(name);
72
		/* Don't block the VM from exiting */
73
		this.setDaemon(true);
74
	}
75
76
	/**
77
	 * Console constructor comment.
78
	 * 
79
	 * @param group
80
	 *            java.lang.ThreadGroup
81
	 * @param name
82
	 *            java.lang.String
83
	 */
84
	public Console(ThreadGroup group, String name) {
85
		super(group, name);
86
		/* Don't block the VM from exiting */
87
		this.setDaemon(true);
88
	}
89
90
	/**
91
	 * Insert the method's description here. Creation date: (2/19/01 2:44:15 PM)
92
	 * 
93
	 * @return long
94
	 */
95
	public long getIP() throws ConsoleNotStartedException {
96
		if (_ip == 0) {
97
			throw new ConsoleNotStartedException();
98
		}
99
		return _ip;
100
	}
101
102
	/**
103
	 * Insert the method's description here. Creation date: (2/19/01 2:43:59 PM)
104
	 * 
105
	 * @return long
106
	 */
107
	public long getPort() throws ConsoleNotStartedException {
108
		if (_port == 0) {
109
			throw new ConsoleNotStartedException();
110
		}
111
		return _port;
112
	}
113
114
	/**
115
	 * Return the server socket used by the console thread
116
	 * 
117
	 * @return java.net.ServerSocket
118
	 * @throws ConsoleNotStartedException
119
	 */
120
	public ServerSocket getServerSocket() throws ConsoleNotStartedException {
121
		if (_sock == null) {
122
			throw new ConsoleNotStartedException(); /* 9707 */
123
		}
124
125
		return _sock;
126
	}
127
128
	/**
129
	 * Insert the method's description here. Creation date: (2/19/01 2:43:25 PM)
130
	 */
131
	public void run() {
132
		byte[] buffer = new byte[1024];
133
		short port = 0/* DATA_PORT_NUM_CLIENT */;
134
		boolean started = false;
135
		boolean complete;
136
137
		/* Start the server */
138
		while (!started) {
139
			try {
140
				started = true;
141
				_sock = new ServerSocket(port, 1);
142
			} catch (Exception e) {
143
				port++;
144
				started = false;
145
			}
146
		}
147
148
		/* Store the address information of this console */
149
		_port = _sock.getLocalPort();
150
		InetAddress localHost = null;
151
		try {
152
			localHost = InetAddress.getLocalHost();
153
			byte[] bytes = localHost.getAddress();
154
			_ip = (long) (bytes[3] << 24 & 0xff000000) | (long) (bytes[2] << 16 & 0x00ff0000) | (long) (bytes[1] << 8 & 0x0000ff00) | (long) (bytes[0] & 0x000000ff);
155
		} catch (UnknownHostException e) {
156
			/* Shouldn't happen as we are looking up the localhost */
157
		}
158
159
		/**
160
		 * If server cannot reach to client do not start console server,
161
		 * basically the launch process command will use 0 as IP and port which
162
		 * indicates no console traffic will be brought back to the client side
163
		 * (and therefore no chance for the firewall to block it since the
164
		 * server reach command is indicating this is what will happen if
165
		 * attempted) -- if server can indeed reach to client then proceed
166
		 * typically (using console server)
167
		 */
168
		boolean serverCanReach = false;
169
		try {
170
			org.eclipse.hyades.internal.execution.local.control.NodeImpl node;
171
			node = new org.eclipse.hyades.internal.execution.local.control.NodeImpl(_node.getName(), _node.getAllInetAddresses());
172
			node.connect(_node.getConnection().getPort());
173
174
			IFileManagerExtended fileManager = FileManagerFactory.getInstance().create(node.getConnection());
175
			serverCanReach = fileManager.determineServerReach(localHost.getHostAddress(), (int) this._port);
176
			node.getConnection().disconnect();
177
		} catch (Exception e) {
178
			e.printStackTrace();
179
		}
180
181
		/* Inform the start method we are up */
182
		synchronized (this) {
183
			_started = true;
184
			this.notify();
185
		}
186
187
		if (serverCanReach) {
188
189
			while (_valid) {
190
				InputStream is = null;
191
				_activeConnection = null;
192
				try {
193
					_activeConnection = _sock.accept();
194
					is = _activeConnection.getInputStream();
195
					_activeConnection.setSoTimeout(1000);
196
					complete = false;
197
				} catch (Exception e) {
198
					/* The server socket is toast, return */
199
					return;
200
				}
201
				while (!complete) {
202
					int length = 0;
203
					try {
204
						length = is.read(buffer);
205
					} catch (InterruptedIOException e) {
206
						/* Read timeout, don't want to wait too long */
207
						if (_processor != null) {
208
							_processor.waitingForData();
209
						}
210
					} catch (IOException e) {
211
						try {
212
							_activeConnection.close();
213
						} catch (IOException e1) {
214
						}
215
						complete = true;
216
					}
217
218
					/* Is the connection closed? */
219
					if (length < 0) {
220
						try {
221
							_activeConnection.close();
222
						} catch (IOException e) {
223
						}
224
						complete = true;
225
					} else if (length > 0) {
226
						if (_processor != null) {
227
							_processor.incommingData(buffer, length, _activeConnection.getInetAddress());
228
						}
229
					}
230
231
					/* Have we been asked to stop. */
232
					if (!_valid) {
233
						try {
234
							_activeConnection.close();
235
						} catch (IOException e1) {
236
						}
237
						complete = true;
238
					}
239
				}
240
			}
241
242
		} else {
243
244
			/*
245
			 * If server cannot reach back, close new server socket and reset ip
246
			 * and port to zero, these values will be attached to the launch
247
			 * process command, if they are zero then server will not attempt to
248
			 * connect to console started in this object
249
			 */
250
			this._ip = 0;
251
			this._port = 0;
252
			this.close();
253
254
		}
255
256
	}
257
258
	public void setDataProcessor(DataProcessor processor) {
259
		_processor = processor;
260
261
	}
262
263
	public DataProcessor getDataProcessor() {
264
		return _processor;
265
	}
266
267
	/**
268
	 * Insert the method's description here. Creation date: (2/19/01 5:39:25 PM)
269
	 */
270
	public void start() {
271
		/* We need to wait until the server is fully up */
272
		synchronized (this) {
273
			_valid = true;
274
			super.start();
275
			do {
276
				try {
277
					this.wait();
278
				} catch (InterruptedException e) {
279
				}
280
			} while (!_started);
281
		}
282
	}
283
284
	/**
285
	 * Insert the method's description here. Creation date: (5/28/01 8:01:54 PM)
286
	 * 
287
	 * @param data
288
	 *            java.lang.String
289
	 */
290
	public void write(String data) {
291
		if (_activeConnection != null) {
292
			try {
293
				_activeConnection.getOutputStream().write(data.getBytes("UTF-8")); // Bug
294
																					// 73074
295
			} catch (Exception e) {
296
			}
297
		}
298
	}
299
300
	/* Closes this console */
301
	public void close() {
302
		if (_sock != null) {
303
			try {
304
				_sock.close();
305
			} catch (IOException e) {
306
			}
307
		}
308
		_valid = false;
309
	}
310
311
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/NotImplementedException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: NotImplementedException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class NotImplementedException extends RuntimeException {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 8162168654381613705L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/BinaryCustomCommand.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: BinaryCustomCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class BinaryCustomCommand extends CustomCommand {
16
17
	public BinaryCustomCommand() {
18
		super();
19
		_tag = RA_BINARY_CUSTOM_COMMAND;
20
	}
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/AgentActiveException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentActiveException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class AgentActiveException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 892731289626728413L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/QueryProcessListCommand.java (+45 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: QueryProcessListCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class QueryProcessListCommand extends CommandElement implements Constants {
16
17
	/**
18
	 * QueryProcessList constructor comment.
19
	 */
20
	public QueryProcessListCommand() {
21
		super();
22
		_tag = RA_QUERY_PROCESS_LIST;
23
	}
24
25
	/**
26
	 * getSize method comment.
27
	 */
28
	public int getSize() {
29
		return super.getSize();
30
	}
31
32
	/**
33
	 * readFromBuffer method comment.
34
	 */
35
	public int readFromBuffer(byte[] buffer, int offset) {
36
		return super.readFromBuffer(buffer, offset);
37
	}
38
39
	/**
40
	 * writeToBuffer method comment.
41
	 */
42
	public int writeToBuffer(byte[] buffer, int offset) {
43
		return super.writeToBuffer(buffer, offset);
44
	}
45
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ManageFileCommand.java (+93 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ManageFileCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.local.common;
13
14
public class ManageFileCommand extends CommandElement implements Constants {
15
	public static final int GET = 0x01;
16
	public static final int PUT = 0x02;
17
	public static final int DELETE = 0x03;
18
19
	private long _operation;
20
	private RAString _filename = new RAString("");;
21
22
	public ManageFileCommand() {
23
		super();
24
		_tag = RA_MANAGE_FILE;
25
	}
26
27
	public int getSize() {
28
		int size = super.getSize();
29
30
		size += sizeofLong; // operation
31
		size += _filename.getSize();
32
33
		return size;
34
	}
35
36
	/**
37
	 * @return long - the operation
38
	 */
39
	public long getOperation() {
40
		return _operation;
41
	}
42
43
	/**
44
	 * @return RAString - the file name
45
	 */
46
	public String getFilename() {
47
		if (_filename != null)
48
			return _filename.getData();
49
		return null;
50
	}
51
52
	/**
53
	 * set the operation to be performed.
54
	 * 
55
	 * @param operation
56
	 */
57
	public void setOperation(long operation) {
58
		_operation = operation;
59
	}
60
61
	/**
62
	 * set file name to be passed to RAC
63
	 * 
64
	 * @param filename
65
	 */
66
	public void setFilename(String filename) {
67
		_filename = new RAString(filename);
68
	}
69
70
	public int readFromBuffer(byte[] buffer, int offset) {
71
		int current = offset;
72
73
		current = super.readFromBuffer(buffer, current);
74
75
		_operation = Message.readRALongFromBuffer(buffer, current);
76
		current += sizeofLong;
77
78
		current = Message.readRAStringFromBuffer(buffer, current, _filename);
79
80
		return current;
81
	}
82
83
	public int writeToBuffer(byte[] buffer, int offset) {
84
		int current = offset;
85
86
		current = super.writeToBuffer(buffer, current);
87
		current = Message.writeRALongToBuffer(buffer, current, _operation);
88
		current = Message.writeRAStringToBuffer(buffer, current, _filename);
89
90
		return current;
91
	}
92
93
}
(-)src-local-public/org/eclipse/hyades/execution/core/file/socket/ISocketChannelFactory.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ISocketChannelFactory.java,v 1.5 2006/10/30 18:25:55 jptoomey Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.hyades.execution.core.file.socket;
14
15
import java.io.IOException;
16
import java.net.InetSocketAddress;
17
import java.net.Socket;
18
19
/**
20
 * The socket channel factory creates socket channel objects given some seed information such as socket, real channel or connection information to establish a new socket channel.
21
 * 
22
 * @author Scott E. Schneider
23
 */
24
public interface ISocketChannelFactory {
25
	/**
26
	 * Creates a local socket channel abstraction over a new socket to be established at the given internet socket address, basically connects to the address given, establishes a socket to the other side and returns back an abstraction to manipulate the connection with -- this method creates a new connection at the given address or returns back an existing connection that is not in use (with no contention with another client possible)
27
	 * 
28
	 * @param address
29
	 *            the address to establish a connection to
30
	 * @return a new socket channel to use
31
	 * @throws IOException
32
	 *             throws an IO exception if socket problems arise
33
	 */
34
	public ISocketChannel create(InetSocketAddress address) throws IOException;
35
36
	/**
37
	 * Creates a local socket channel abstraction over a new socket to be established at the given internet socket address, basically connects to the address given, establishes a socket to the other side and returns back an abstraction to manipulate the connection with -- this method creates a new connection at the given address or returns back an existing connection that is not in use (with no contention with another client possible)
38
	 * 
39
	 * @param address
40
	 *            the address to establish a connection to
41
	 * @param timeout
42
	 *            timeout to use for the connection
43
	 * @return a new socket channel to use
44
	 * @throws IOException
45
	 *             throws an IO exception if socket problems arise
46
	 */
47
	public ISocketChannel create(InetSocketAddress address, int timeout) throws IOException;
48
49
	/**
50
	 * Creates a local socket channel abstraction for the given standard channel, this does not create a new connection, simply wraps a java.nio channel with a local abstraction
51
	 * 
52
	 * @param realChannel
53
	 *            the standard Java abstraction
54
	 * @return the local socket channel interface, abstracting the real socket channel and associated socket
55
	 */
56
	public ISocketChannel create(java.nio.channels.SocketChannel realChannel);
57
58
	/**
59
	 * Creates a local socket channel abstraction for the given socket, this does not create a new connection, simply wraps a java.nio channel with a local abstraction
60
	 * 
61
	 * @param socket
62
	 *            the socket to seed this socket channel
63
	 * @return the local socket channel interface abstacting an already existing socket
64
	 * @throws an
65
	 *             IO exception if socket problems arise
66
	 */
67
	public ISocketChannel create(Socket socket) throws IOException;
68
}
(-)src-local-public/org/eclipse/hyades/execution/core/file/socket/SocketChannel.java (+161 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: SocketChannel.java,v 1.4 2006/10/30 18:25:55 jptoomey Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.hyades.execution.core.file.socket;
14
15
import java.io.IOException;
16
import java.net.Socket;
17
import java.nio.ByteBuffer;
18
import java.nio.channels.Channel;
19
import java.nio.channels.Channels;
20
import java.nio.channels.ReadableByteChannel;
21
import java.nio.channels.WritableByteChannel;
22
23
/**
24
 * An abstraction above the socket channel to allow a socket channel to be emulated by taking a readable byte channel and a writeable byte channel and combining them into a new interface. Socket channel is a class and not an interface in Java, so an interface and an adapter class implementation is introduced to satisfy our purposes.
25
 * 
26
 * A socket channel instance can be created from a standard socket or from a standard channel.
27
 * 
28
 * @see org.eclipse.hyades.execution.core.file.socket.ISocketChannel
29
 * 
30
 * @author Scott E. Schneider
31
 */
32
class SocketChannel implements ISocketChannel {
33
34
	/**
35
	 * An adapter that adapts a socket to look like a channel. A simple interface is exposed to clients with the is open and close methods.
36
	 * 
37
	 * @author Scott E. Schneider
38
	 */
39
	private class ChannelInterfaceAdapter implements Channel {
40
41
		/*
42
		 * (non-Javadoc)
43
		 * 
44
		 * @see java.nio.channels.Channel#close()
45
		 */
46
		public void close() throws IOException {
47
			SocketChannel.this.socket.close();
48
		}
49
50
		/*
51
		 * (non-Javadoc)
52
		 * 
53
		 * @see java.nio.channels.Channel#isOpen()
54
		 */
55
		public boolean isOpen() {
56
			return !SocketChannel.this.socket.isClosed();
57
		}
58
59
	}
60
61
	/**
62
	 * The channel interface where all channel interface calls are delegated to
63
	 */
64
	private final Channel channel;
65
66
	/**
67
	 * The readable byte channel, all readable byte channel interface invocations are delegated to this instance
68
	 */
69
	private final ReadableByteChannel readable;
70
71
	/**
72
	 * The underlying socket for this socket channel
73
	 */
74
	private final Socket socket;
75
76
	/**
77
	 * The writable byte channel, all writable byte channel interface invocations are delegate to this instance
78
	 */
79
	private final WritableByteChannel writable;
80
81
	/**
82
	 * For a standard "real" channel from java.nio, simply store the instance in three interface-held variables, used by the corresponding methods in this class to adapt the calls (just re-forward them into the appropriate delegates in most cases)
83
	 * 
84
	 * @param realChannel
85
	 *            the real channel obtained from the socket channel related classes in java.nio
86
	 */
87
	SocketChannel(java.nio.channels.SocketChannel realChannel) {
88
		this.channel = realChannel;
89
		this.readable = realChannel;
90
		this.writable = realChannel;
91
		this.socket = realChannel.socket();
92
	}
93
94
	/**
95
	 * A socket channel emulation is created given a standard socket, this constructor will take the socket, obtain input and output streams and then using the java.nio utility class it will create channels from these. For the main channel interface it will adapt these appropriately to the underlying socket here
96
	 * 
97
	 * @param socket
98
	 *            the socket that is abstracted by the socket channel instance
99
	 */
100
	SocketChannel(Socket socket) throws IOException {
101
		this.channel = new ChannelInterfaceAdapter();
102
		this.readable = Channels.newChannel(socket.getInputStream());
103
		this.writable = Channels.newChannel(socket.getOutputStream());
104
		this.socket = socket;
105
	}
106
107
	/*
108
	 * (non-Javadoc)
109
	 * 
110
	 * @see java.nio.channels.Channel#close()
111
	 */
112
	public void close() throws IOException {
113
		if (this.socket != null) {
114
			socket.close();
115
		}
116
		if (this.channel != null) {
117
			this.channel.close();
118
		}
119
		if (this.readable != null) {
120
			this.readable.close();
121
		}
122
		if (this.writable != null) {
123
			this.writable.close();
124
		}
125
	}
126
127
	/**
128
	 * Returns the underlying socket for this socket channel
129
	 */
130
	public Socket getSocket() {
131
		return this.socket;
132
	}
133
134
	/*
135
	 * (non-Javadoc)
136
	 * 
137
	 * @see java.nio.channels.Channel#isOpen()
138
	 */
139
	public boolean isOpen() {
140
		return this.channel.isOpen();
141
	}
142
143
	/*
144
	 * (non-Javadoc)
145
	 * 
146
	 * @see java.nio.channels.ReadableByteChannel#read(java.nio.ByteBuffer)
147
	 */
148
	public int read(ByteBuffer buffer) throws IOException {
149
		return this.readable.read(buffer);
150
	}
151
152
	/*
153
	 * (non-Javadoc)
154
	 * 
155
	 * @see java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
156
	 */
157
	public int write(ByteBuffer buffer) throws IOException {
158
		return this.writable.write(buffer);
159
	}
160
161
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Node.java (+144 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Node.java,v 1.4 2006/12/14 23:11:18 jptoomey Exp $
8
 * 
9
 * Contributors: IBM - Initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.hyades.execution.local.control;
13
14
import java.net.InetAddress;
15
import java.util.Enumeration;
16
17
import org.eclipse.hyades.execution.security.ISecureClientParameters;
18
import org.eclipse.hyades.execution.local.common.SetNVPairCommand;
19
import org.eclipse.hyades.execution.security.LoginFailedException;
20
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
21
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
22
import org.eclipse.hyades.execution.security.User;
23
24
public interface Node extends CommandHandler {
25
26
    /**
27
     * Terminates the specified process on this node.
28
     */
29
    void killProcess(Process process) throws InactiveProcessException,
30
            NotConnectedException;
31
32
    /**
33
     * Causes this node to shutdown after the specified number of seconds.
34
     */
35
    void shutdown(long delay) throws NotConnectedException;
36
37
    /**
38
     * Causes this node to reboot after the specified number of seconds.
39
     */
40
    void reboot(long delay) throws NotConnectedException;
41
42
    /**
43
     * Enumerate all the monitors on this node.
44
     */
45
    Enumeration listMonitors() throws NotConnectedException;
46
47
    /**
48
     * Enumerate all the active processes on this node.
49
     * 
50
     * This method has side effects of storing the process list within
51
	 * the node, populating the agents within each process in that list 
52
	 * and retrieving the details of each agent in each process.
53
     */
54
    Enumeration listProcesses() throws NotConnectedException;
55
56
	/**
57
     * Enumerate all the active processes on this node.
58
	 * 
59
	 * This method has side effects of storing the process list within
60
	 * the node and populating the agents within each process in that list 
61
	 * Unlike the listProcesses() method, it does *not* retrieve the details
62
	 * for each agent.
63
	 */
64
    Enumeration fastListProcesses() throws NotConnectedException;
65
66
    /**
67
     * Enumerate all the properties on this node.
68
     */
69
    SetNVPairCommand[] getPropertyValues(String name, String type)
70
            throws NotConnectedException;
71
72
    /**
73
     * Retrieve a specific Process on this Node
74
     */
75
    Process getProcess(String processId);
76
77
    /**
78
     * Retrieve the InetAddress for this Node.
79
     */
80
    InetAddress getInetAddress();
81
82
    /**
83
     * Retrives all the InetAddresses for this Node.
84
     */
85
    InetAddress[] getAllInetAddresses();
86
87
    /**
88
     * Retrieve the host name for this Node.
89
     */
90
    String getName();
91
92
    /**
93
     * Is this controller connected to this node
94
     */
95
    boolean isConnected();
96
97
    /**
98
     * Attempt to connect to this node.
99
     */
100
    Connection connect(int port) throws AgentControllerUnavailableException,
101
            SecureConnectionRequiredException,
102
            UntrustedAgentControllerException, LoginFailedException;
103
104
    /**
105
     * Retrieve the connection associated with this node object
106
     */
107
    Connection getConnection();
108
109
    /**
110
     * Retrieve the user for this node.
111
     */
112
    User getUser();
113
114
    /**
115
     * Update the user for this node.
116
     */
117
    void setUser(User user);
118
119
    /**
120
     * Blocks calling thread until the process is retrieved, if the process
121
     * cannot be retrieved within the timeout period, null is returned for the
122
     * process return value.
123
     * 
124
     * @param processIdentity
125
     *            the identity of the process to wait for
126
     * @param timeout
127
     *            the maximum time to wait for the process to be retrieved
128
     * @return the process retrieved or null if the timeout is reached before
129
     *         the process is found
130
     * @throws NotConnectedException
131
     */
132
    Process waitForProcess(String processIdentity, int timeout)
133
            throws NotConnectedException, InactiveProcessException;
134
135
    void setApplication(Application app);
136
137
    Application getApplication();
138
139
    void setSecurityParameters(ISecureClientParameters manager);
140
141
    ISecureClientParameters getSecurityParameters();
142
143
}
144
(-)src-local-public/org/eclipse/hyades/execution/local/common/AuthenticationSuccessfulCommand.java (+58 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AuthenticationSuccessfulCommand.java,v 1.4 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AuthenticationSuccessfulCommand extends CommandElement implements Constants {
16
	private RAString _key = new RAString("");
17
18
	public AuthenticationSuccessfulCommand() {
19
		super();
20
		_tag = RA_AUTHENTICATION_SUCCESSFUL;
21
	}
22
23
	public int getSize() {
24
		int size = super.getSize();
25
26
		size += _key.getSize();
27
28
		return size;
29
	}
30
31
	public int readFromBuffer(byte[] buffer, int offset) {
32
		int current = offset;
33
34
		/*
35
		 * Cannot call super.readFromBuffer() since this command does not have a
36
		 * context
37
		 */
38
		// current = super.readFromBuffer(buffer, current);
39
		current = Message.readRAStringFromBuffer(buffer, current, _key);
40
41
		return current;
42
	}
43
44
	public int writeToBuffer(byte[] buffer, int offset) {
45
		int current = offset;
46
47
		/*
48
		 * Cannot call super.writeToBuffer() since this command does not have a
49
		 * context
50
		 */
51
		// current = super.writeToBuffer(buffer, current);
52
		current = Message.writeRALongToBuffer(buffer, current, _tag);
53
		current = Message.writeRAStringToBuffer(buffer, current, _key);
54
55
		return current;
56
	}
57
58
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/InactiveProcessException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: InactiveProcessException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class InactiveProcessException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 5117230334515885419L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Process.java (+168 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Process.java,v 1.4 2005/09/27 20:31:58 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.util.Enumeration;
16
17
import org.eclipse.hyades.execution.local.common.Console;
18
19
public interface Process {
20
21
	/**
22
	 * Launches the process on the node that was provided to the ProcessFactory during construction of this Process instance. If the Process was already launched the ProcessActiveException is thrown.
23
	 */
24
	void launch() throws ProcessActiveException, NotConnectedException, NoSuchApplicationException;
25
26
	/**
27
	 * Kills this process if it is active.
28
	 */
29
	void kill(long delay) throws InactiveProcessException, NotConnectedException;
30
31
	/**
32
	 * Provides an Enumeration of all the Agents associated with this Process instance.
33
	 * 
34
	 * @see Agent
35
	 */
36
	Enumeration listAgents();
37
38
	/**
39
	 * Retrieves an agent based upon it's name
40
	 * 
41
	 * @see Agent
42
	 * @return the agent with the specified name if it exists, null otherwise
43
	 */
44
	Agent getAgent(String name);
45
46
	/**
47
	 * Provides an enumeration of all the agents of a specific type that are assciated with this Process.
48
	 */
49
	Enumeration getAgentsByType(String type);
50
51
	/**
52
	 * Adds a ProcessListener to this Process instance.
53
	 * 
54
	 * @see ProcessListener
55
	 */
56
	void addProcessListener(ProcessListener listener);
57
58
	/**
59
	 * Removes a ProcessListener from this Process instance.
60
	 * 
61
	 * @see ProcessListener
62
	 */
63
	void removeProcessListener(ProcessListener listener);
64
65
	/**
66
	 * Retrieves the Node that this Process instance is associated with.
67
	 * 
68
	 * @see Node
69
	 */
70
	Node getNode() throws InactiveProcessException;
71
72
	/**
73
	 * Save a user friendly name so that it can be retrieved later via Process#getName()
74
	 */
75
	void setName(String name);
76
77
	/**
78
	 * Retrieves the name of this process as provided by Process#setName()
79
	 */
80
	String getName();
81
82
	/**
83
	 * Retrieves the uuid of this process if it is known, null otherwise.
84
	 */
85
	String getUUID();
86
87
	void setUUID(String uuid);
88
89
	/**
90
	 * Set the exectauble name for this process.
91
	 */
92
	void setExecutable(String exe) throws ProcessActiveException;
93
94
	/**
95
	 * Get the exectable name for this process.
96
	 */
97
	String getExecutable();
98
99
	/**
100
	 * Retrieve the process ID (pid) for this process
101
	 */
102
	String getProcessId() throws InactiveProcessException;
103
104
	void setProcessId(String pid);
105
106
	boolean isActive();
107
108
	void setActive(boolean isActive);
109
110
	/**
111
	 * Retrieves the console of this Process instance.
112
	 */
113
	Console getConsole();
114
115
	/**
116
	 * Adds an environment variable to this process.
117
	 */
118
	void addEnvironmentVariable(Variable variable) throws ProcessActiveException;
119
120
	/**
121
	 * Retrieves an environment variable from this process.
122
	 * 
123
	 * @return the environment variable with the specified name attribute if it exists, null otherwise.
124
	 */
125
	Variable getEnvironmentVariable(String name);
126
127
	/**
128
	 * Removes an environment variable from this process.
129
	 */
130
	void removeEnvironmentVariable(Variable variable) throws ProcessActiveException;
131
132
	/**
133
	 * Provides an enumeration of each Variabe comprising the entire environment of this process.
134
	 * 
135
	 * @see Variable
136
	 */
137
	Enumeration getEnvironment();
138
139
	/**
140
	 * Set the parameters for this process
141
	 */
142
	void setParameters(String parameters) throws ProcessActiveException;
143
144
	/**
145
	 * Retrieves the parameters of the process.
146
	 */
147
	String getParameters();
148
149
	/**
150
	 * Set's the home directory of the process.
151
	 */
152
	void setLocation(String location) throws ProcessActiveException;
153
154
	/**
155
	 * Blocks calling thread until the agent is retrieved, if the agent cannot be retrieved within the timeout period, null is returned for the agent return value.
156
	 * 
157
	 * @param agentType
158
	 *            the type of agent qualified the selection
159
	 * @param agentName
160
	 *            the name of the agent to wait for
161
	 * @param timeout
162
	 *            the maximum time to wait for the agent to be retrieved
163
	 * @return the agent retrieved or null if the timeout is reached before the agent is found
164
	 * @throws NotConnectedException
165
	 */
166
	Agent waitForAgent(String agentType, String agentName, int timeout) throws NotConnectedException, InactiveProcessException;
167
168
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/ContextMapper.java (+98 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ContextMapper.java,v 1.4 2005/10/01 23:42:33 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class ContextMapper {
16
	protected final static int MAPPING_INCREMENT = 10;
17
18
	protected ContextMap[] _map = new ContextMap[MAPPING_INCREMENT];
19
	protected int _mappingCount = 0;
20
	protected int _maxMappingCount = 0;
21
22
	class ContextMap {
23
		public long _context = 0;
24
		public CommandHandler _handler = null;
25
		public boolean _dirty = false;
26
	}
27
28
	public ContextMapper() {
29
		super();
30
	}
31
32
	public void addContext(long contextId, CommandHandler handler) {
33
		synchronized (_map) {
34
			if (_maxMappingCount == _map.length) {
35
				increaseContextmappingCapacity();
36
			}
37
			for (int i = _mappingCount; i >= 0; i--) {
38
				if (_map[i] == null) {
39
					_mappingCount++;
40
					_maxMappingCount++;
41
					_map[i] = new ContextMap();
42
					_map[i]._context = contextId;
43
					_map[i]._handler = handler;
44
					_map[i]._dirty = true;
45
					return;
46
				} else if (!_map[i]._dirty) {
47
					_mappingCount++;
48
					_map[i]._context = contextId;
49
					_map[i]._handler = handler;
50
					_map[i]._dirty = true;
51
					return;
52
				}
53
			}
54
		}
55
	}
56
57
	public CommandHandler getHandler(long contextid) {
58
		CommandHandler ch = null;
59
		synchronized (_map) {
60
			for (int i = _maxMappingCount - 1; i >= 0; i--) {
61
				if (_map[i] == null) {
62
					/* This should never happen */
63
					break;
64
				}
65
				if (_map[i]._context == contextid && _map[i]._dirty == true) {
66
					ch = _map[i]._handler;
67
					break;
68
				}
69
			}
70
		}
71
		return ch;
72
	}
73
74
	protected void increaseContextmappingCapacity() {
75
		synchronized (_map) {
76
			ContextMap[] newMapper = new ContextMap[_maxMappingCount + MAPPING_INCREMENT];
77
			for (int i = 0; i < _maxMappingCount; i++) {
78
				newMapper[i] = _map[i];
79
			}
80
			_map = newMapper;
81
			newMapper = null;
82
		}
83
	}
84
85
	public void removeContext(long contextId) {
86
		synchronized (_map) {
87
			for (int i = _maxMappingCount - 1; i >= 0; i--) {
88
				if (_map[i]._context == contextId && _map[i]._dirty == true) {
89
					_mappingCount--;
90
					_map[i]._dirty = false;
91
					_map[i]._handler = null;
92
					break;
93
				}
94
			}
95
		}
96
97
	}
98
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/AgentInactiveCommand.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: AgentInactiveCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class AgentInactiveCommand extends DetailedAgentInfoCommand {
16
17
	/**
18
	 * VMExitingCommand constructor comment.
19
	 */
20
	public AgentInactiveCommand() {
21
		super();
22
		_tag = RA_AGENT_INACTIVE;
23
	}
24
25
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/ProcessExitedCommand.java (+21 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: ProcessExitedCommand.java,v 1.2 2005/02/25 22:17:09 hleung Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public class ProcessExitedCommand extends SimpleProcessCommand {
16
17
	public ProcessExitedCommand() {
18
		super();
19
		_tag = RA_PROCESS_EXITED;
20
	}
21
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/NotConnectedException.java (+22 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: NotConnectedException.java,v 1.4 2005/10/08 14:28:51 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
public class NotConnectedException extends Exception {
16
17
	/**
18
	 * Stream-Unique IDentifier (SUID) of this class
19
	 */
20
	private static final long serialVersionUID = 1657617474248494436L;
21
22
}
(-)src-local-public/org/eclipse/hyades/execution/local/control/Connection.java (+65 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Connection.java,v 1.3 2005/09/13 16:46:20 sschneid Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.control;
14
15
import java.io.IOException;
16
17
import org.eclipse.hyades.execution.local.common.ControlMessage;
18
import org.eclipse.hyades.execution.security.AuthenticationListener;
19
import org.eclipse.hyades.execution.security.LoginFailedException;
20
import org.eclipse.hyades.execution.security.SecureConnectionRequiredException;
21
import org.eclipse.hyades.execution.security.UntrustedAgentControllerException;
22
23
public interface Connection {
24
25
	void sendMessage(ControlMessage msg, CommandHandler handler) throws IOException;
26
27
	void disconnect();
28
29
	Node getNode();
30
31
	boolean isActive();
32
33
	int getPort();
34
35
	/**
36
	 * Adds a ConnectionListener to this Connection instance.
37
	 * 
38
	 * @see ConnectionListener
39
	 */
40
	void addConnectionListener(ConnectionListener listener);
41
42
	/**
43
	 * Removes a ConnectionListener from this Connection instance.
44
	 * 
45
	 * @see ConnectionListener
46
	 */
47
	void removeConnectionListener(ConnectionListener listener);
48
49
	/**
50
	 * Adds an AuthenticationListener to this connection.
51
	 * 
52
	 * @see AuthenticationListener
53
	 */
54
	void addAuthenticationListener(AuthenticationListener listener);
55
56
	/**
57
	 * Removes an AuthenticationListener from this connection.
58
	 * 
59
	 * @see AuthenticationListener
60
	 */
61
	void removeAuthenticationListener(AuthenticationListener listener);
62
63
	void connect(Node node, int port) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException;
64
65
}
(-)src-local-public/org/eclipse/hyades/execution/local/common/DetailedAgentInfoCommand.java (+80 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: DetailedAgentInfoCommand.java,v 1.5 2006/04/06 15:28:00 samwai Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.local.common;
14
15
public abstract class DetailedAgentInfoCommand extends DetailedProcessCommand implements Constants {
16
	protected RAString _agentName = new RAString("");
17
	protected RAString _agentUUID = new RAString("");
18
	protected RAString _agentType = new RAString("");
19
20
	/**
21
	 * ProcessInfoCommandEntry constructor comment.
22
	 */
23
	public DetailedAgentInfoCommand() {
24
		super();
25
	}
26
27
	public String getAgentName() {
28
		if (_agentName != null)
29
			return _agentName.getData();
30
		return null;
31
	}
32
33
	public void setAgentName(String name) {
34
		_agentName = new RAString(name);
35
	}
36
37
	public String getAgentType() {
38
		if (_agentType != null) {
39
			return _agentType.getData();
40
		}
41
		return null;
42
	}
43
44
	public void setAgentType(String type) {
45
		_agentType = new RAString(type);
46
	}
47
48
	public String getAgentUUID() {
49
		if (_agentUUID != null) {
50
			return _agentUUID.getData();
51
		}
52
		return null;
53
	}
54
55
	public void setAgentUUID(String uuid) {
56
		_agentUUID = new RAString(uuid);
57
	}
58
59
	public int getSize() {
60
		return super.getSize() + _agentName.getSize() + _agentUUID.getSize() + _agentType.getSize();
61
	}
62
63
	public int readFromBuffer(byte[] buffer, int offset) {
64
		int current = super.readFromBuffer(buffer, offset);
65
		current = Message.readRAStringFromBuffer(buffer, current, _agentName);
66
		current = Message.readRAStringFromBuffer(buffer, current, _agentUUID);
67
		current = Message.readRAStringFromBuffer(buffer, current, _agentType);
68
		return current;
69
	}
70
71
	public int writeToBuffer(byte[] buffer, int offset) {
72
		int current = super.writeToBuffer(buffer, offset);
73
74
		current = Message.writeRAStringToBuffer(buffer, current, _agentName);
75
		current = Message.writeRAStringToBuffer(buffer, current, _agentUUID);
76
		current = Message.writeRAStringToBuffer(buffer, current, _agentType);
77
78
		return current;
79
	}
80
}
(-)src-local-public/org/eclipse/hyades/execution/file/FileServiceConstants.java (+44 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: FileServiceConstants.java,v 1.3 2005/05/20 22:53:09 jptoomey Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.execution.file;
13
14
/**
15
 * @author Giridhar.S
16
 * 
17
 * This interface defines constants required for implementing file service.
18
 * 
19
 */
20
public interface FileServiceConstants {
21
22
	public final static int RA_BUFFER_SIZE = 1024;
23
24
	/* The static return values for possible exceptions we may have to catch */
25
26
	public static final int RA_ERROR = -1;
27
	public static final int SECURE_CONNECTION_REQUIRED_EXCEPTION = -2;
28
	public static final int UNTRUSTED_AGENT_CONTROLLER_EXCEPTION = -3;
29
	public static final int AGENT_CONTROLLER_UNAVAILABLE_EXCEPTION = -4;
30
	public static final int LOGIN_FAILED_EXCEPTION = -5;
31
	public static final int UNKNOWN_HOST_EXCEPTION = -6;
32
	public static final int CONNECT_EXCEPTION = -7;
33
	public final static int RA_FILE_NOT_FOUND_ERROR = -8;
34
	public final static int RA_IO_ERROR = -9;
35
	public final static int RA_BIND_EXCEPTION = -10;
36
37
	/* Values to represent the state of the file server */
38
	public final static int RA_FS_STATUS_OK = 0;
39
	public final static int RA_FS_STATUS_ERROR = -1;
40
41
	/* Values to represent the initialization status of the file server */
42
	public final static int RA_FS_UNINITIALIZED = 0;
43
	public final static int RA_FS_INITIALIZED = 1;
44
}

Return to bug 136985