Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbridgha2006-02-24 19:00:48 +0000
committercbridgha2006-02-24 19:00:48 +0000
commita5a5a7da3dc35ff771aec8dc35776a98f595bfa3 (patch)
treed901c988e7e2c2f545bbcd28380d7b77af07084b /plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote
parent672c7efdf18ab8c71b2d2eabe6f853a66126d03a (diff)
downloadwebtools.javaee-20060224a.tar.gz
webtools.javaee-20060224a.tar.xz
webtools.javaee-20060224a.zip
This commit was manufactured by cvs2svn to create tag 'v20060224a'.v20060224a
Diffstat (limited to 'plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote')
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/AWTStarter.java35
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ArrayHelper.java71
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackHandler.java181
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackOutputStream.java155
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ClassHelper.java48
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionHandler.java926
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionThread.java53
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ExpressionProcesserController.java809
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/IdentityMap.java96
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMApplication.java45
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMServerThread.java717
-rw-r--r--plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/StackTraceUtility.java32
12 files changed, 0 insertions, 3168 deletions
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/AWTStarter.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/AWTStarter.java
deleted file mode 100644
index 761f48edf..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/AWTStarter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * $RCSfile: AWTStarter.java,v $
- * $Revision: 1.1 $ $Date: 2005/05/11 19:01:12 $
- */
-package org.eclipse.jem.internal.proxy.vm.remote;
-
-import java.awt.Toolkit;
-
-
-/**
- * This class is used to do start the AWT eventqueue ahead of time to try to parallel process it.
- * @since 1.1.0
- */
-public class AWTStarter {
-
- public static void startAWT() {
- Thread t = new Thread() {
- public void run() {
- Thread.yield(); // So as not to possibly hold up the guy doing the starting.
- Toolkit.getDefaultToolkit();
- }
- };
- t.start();
- }
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ArrayHelper.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ArrayHelper.java
deleted file mode 100644
index 94422237f..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ArrayHelper.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: ArrayHelper.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-
-/**
- * This class provides similiar function as the java.lang.reflect.Array class but
- * it handles multi-dimensional arrays. Without this helper, the client would have
- * to walk down through each dimension executing a get command. This would mean
- * many transactions instead of one provided by this helper.
- *
- * It also provides some other helper functions for arrays that Array doesn't provide.
- */
-
-public final class ArrayHelper {
- // It can never be instantiated.
- private ArrayHelper() {
- }
-
- public static Object get(Object array, int[] indexes) {
- Object answer = array;
- for (int i=0; i<indexes.length; i++)
- answer = java.lang.reflect.Array.get(answer, indexes[i]);
- return answer;
- }
-
- public static byte getByte(Object array, int[] indexes) {
- return ((Byte) get(array, indexes)).byteValue();
- }
- public static boolean getBoolean(Object array, int[] indexes) {
- return ((Boolean) get(array, indexes)).booleanValue();
- }
- public static char getChar(Object array, int[] indexes) {
- return ((Character) get(array, indexes)).charValue();
- }
- public static double getDouble(Object array, int[] indexes) {
- return ((Double) get(array, indexes)).doubleValue();
- }
- public static float getFloat(Object array, int[] indexes) {
- return ((Float) get(array, indexes)).floatValue();
- }
- public static int getInt(Object array, int[] indexes) {
- return ((Integer) get(array, indexes)).intValue();
- }
- public static long getLong(Object array, int[] indexes) {
- return ((Long) get(array, indexes)).longValue();
- }
- public static short getShort(Object array, int[] indexes) {
- return ((Short) get(array, indexes)).shortValue();
- }
-
- public static void set(Object array, int[] indexes, Object value) {
- Object subArray = array;
- int upTo = indexes.length-1;
- for (int i=0; i<upTo; i++)
- subArray = java.lang.reflect.Array.get(subArray, indexes[i]);
- java.lang.reflect.Array.set(subArray, indexes[upTo], value);
- }
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackHandler.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackHandler.java
deleted file mode 100644
index 4d9665612..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackHandler.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: CallbackHandler.java,v $
- * $Revision: 1.7 $ $Date: 2005/08/24 20:39:08 $
- */
-
-import java.net.Socket;
-import java.io.*;
-import org.eclipse.jem.internal.proxy.common.remote.Commands;
-import org.eclipse.jem.internal.proxy.common.remote.UnexpectedExceptionCommandException;
-import org.eclipse.jem.internal.proxy.common.*;
-/**
- * This is a handler for doing callbacks to the
- * client.
- *
- * This is package protected because no one should
- * use it from the outside. It is too critical that
- * callback's work only in this specified way.
- */
-class CallbackHandler extends ConnectionHandler implements ICallbackHandler {
- public CallbackHandler(Socket sc, RemoteVMServerThread svr) {
- super(sc, svr, null);
- }
-
- /**
- * Initiate a stream callback request.
- */
- public void initiateCallbackStream(int callbackID, int msgID) throws CommandException {
- try {
- Commands.sendCallbackStreamCommand(out, callbackID, msgID);
- out.flush();
- } catch (CommandException e) {
- throw e;
- } catch (Exception e) {
- throw new UnexpectedExceptionCommandException(false, e);
- }
- run(); // Now run and wait for return. If no command exeception thrown, then it signals to continue.
- }
-
- /**
- * Write bytes to the client. If bytesToWrite is -1, then this is end and
- * no bytes are being written. Just write the -1 then.
- */
- public void writeBytes(byte[] bytes, int bytesToWrite) throws CommandException {
- try {
- if (bytesToWrite != -1)
- Commands.writeBytes(out, bytes, bytesToWrite);
- else
- out.writeInt(-1);
- } catch (CommandException e) {
- throw e;
- } catch (Exception e) {
- throw new UnexpectedExceptionCommandException(false, e);
- }
- }
-
-
- /**
- * Callback, but send the parm as an object, ie. it must
- * be nothing but constants, e.g. String, Integer, or an
- * array of constants. Constants should not be things like
- * regular objects. This is because only standard java.lang
- * type constants can be assured to be available on the other
- * client. Also you don't want to send big objects, except
- * maybe something like an array of bytes or strings. It must
- * be constants that don't need to be sent back for any reason
- * since their identity will be lost in the transfer.
- *
- * This should be used if there are no parms (i.e. it is null).
- */
- public Object callbackAsConstants(int callbackID, int msgID, Object parm) throws CommandException {
-
- try {
- Commands.sendCallbackCommand(out, callbackID, msgID);
- Commands.ValueObject v = new Commands.ValueObject();
- sendObject(parm, SEND_AS_IS, v, out, false);
- out.flush();
- } catch (CommandException e) {
- throw e;
- } catch (Exception e) {
- throw new UnexpectedExceptionCommandException(false, e);
- }
- return run(); // Now run and wait for return.
- }
-
-
- // A retriever is what handles the array part.
- private class Retriever implements Commands.ValueRetrieve {
- int index=0;
- Object[] array;
- Commands.ValueObject worker = new Commands.ValueObject();
-
-
- public Retriever(Object[] anArray) {
- array = anArray;
- }
-
- public Commands.ValueObject nextValue() {
- Object parm = array[index++];
- if (parm != null) {
- if (parm instanceof ICallbackHandler.TransmitableArray) {
- // It is another array, create a new retriever.
- worker.setArrayIDS(new Retriever(((ICallbackHandler.TransmitableArray) parm).getArray()), ((ICallbackHandler.TransmitableArray) parm).getArray().length, Commands.OBJECT_CLASS);
- } else {
- // They may add some new ID's and if there is an error, they
- // won't get released, but that is a slight chance we will have
- // to take because we don't know which ones were new and which
- // ones weren't.
- fillInValue(parm, NOT_A_PRIMITIVE, worker);
- }
- } else
- worker.set();
- return worker;
- }
- };
-
- private static final Object[] NULL_SENT = new Object[1];
- /**
- * Callback, but send the parm as IDs so that proxies
- * will be created for the objects and can be referenced.
- *
- * This should be used even if there is only one parm.
- */
- public Object callbackWithParms(int callbackID, int msgID, Object[] parms) throws CommandException {
- try {
- if (parms == null)
- parms = NULL_SENT;
-
- Commands.ValueObject v = new Commands.ValueObject();
-
- v.setArrayIDS(new Retriever(parms), parms.length, Commands.OBJECT_CLASS);
- Commands.sendCallbackCommand(out, callbackID, msgID);
- Commands.writeValue(out, v, false);
- out.flush();
- } catch (CommandException e) {
- throw e;
- } catch (Exception e) {
- throw new UnexpectedExceptionCommandException(false, e);
- }
- return run(); // Now run and wait for return.
- }
-
- /**
- * A closeHandler has been requested. This is called when
- * not waiting within a loop, so we need to do the cleanup ourselves.
- */
- public void closeHandler() {
- if (isConnected()) {
- try {
- Commands.sendQuitCommand(out);
- } catch (IOException e) {
- } finally {
- if (in != null)
- try {
- in.close();
- } catch (Exception e) {
- }
- if (out != null)
- try {
- out.close();
- } catch (Exception e) {
- }
- close();
- in = null;
- out = null;
- socket = null;
- }
- }
- }
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackOutputStream.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackOutputStream.java
deleted file mode 100644
index 238d2c1c6..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/CallbackOutputStream.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: CallbackOutputStream.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-import java.io.OutputStream;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import org.eclipse.jem.internal.proxy.common.CommandException;
-import org.eclipse.jem.internal.proxy.common.remote.IOCommandException;
-/**
- * This is the special stream used to buffer and write a lot
- * of bytes to callback into the client.
- *
- * Before writing any bytes to the client, it will see if the
- * client has sent anything back. If it has, this is an indication
- * that that client has requested that the stream be closed. In that
- * case an InterruptedIOException is raised to indicate that
- * the stream will be closed and no more data will be sent.
- */
-public class CallbackOutputStream extends OutputStream {
-
- protected CallbackHandler fHandler;
- protected RemoteVMServerThread fSvr;
- protected byte[] fBuffer;
- protected int fNextByte = 0;
-
- public CallbackOutputStream(CallbackHandler handler, RemoteVMServerThread svr) {
- fHandler = handler;
- fSvr = svr;
-
- Integer bufSize = Integer.getInteger("proxyvm.bufsize"); //$NON-NLS-1$
- if (bufSize == null)
- bufSize = new Integer(5000);
- fBuffer = new byte[bufSize.intValue()];
- }
-
- protected void clearStream() {
- fSvr.returnCallbackHandler(fHandler);
- fSvr = null;
- fHandler = null;
- fBuffer = null;
- }
-
- protected void processException(CommandException e) throws IOException {
- clearStream();
- throw new IOCommandException(e);
- }
-
- public void flush() throws IOException {
- flushBuffer();
- fHandler.out.flush();
- }
-
- protected void flushBuffer() throws IOException {
- if (fHandler == null)
- throw new IOException("Stream closed. No more operations permitted."); //$NON-NLS-1$
- if (fNextByte > 0) {
- try {
- if (fHandler.in.available() > 0) {
- // There was something waiting. This means a cancel has been requested.
- fHandler.in.skip(fHandler.in.available());
- close(false); // Now close the stream. We need to have the close indicator sent so that the remote side, but we don't need to wait because the terminate response has already been sent.
- throw new InterruptedIOException();
- }
- fHandler.writeBytes(fBuffer, fNextByte);
- fNextByte = 0;
- } catch (CommandException e) {
- processException(e);
- }
- }
- }
-
- /**
- * Closes this output stream and releases any system resources
- * associated with this stream. The general contract of <code>close</code>
- * is that it closes the output stream. A closed stream cannot perform
- * output operations and cannot be reopened.
- * <p>
- * Close will send a -1 to the client and set to indicate it is closed.
- *
- * @exception IOException if an I/O error occurs.
- */
- public void close() throws IOException {
- close(true);
- }
-
-
- protected void close(boolean wait) throws IOException {
- if (fHandler != null) {
- try {
- flushBuffer();
- try {
- fHandler.writeBytes(null, -1);
- fHandler.out.flush();
- if (wait) {
- // Wait means wait for the remote side to send the terminated response.
- // A normal close will do this. If the remote side sent a cancel request, then it has already
- // sent the terminated response and it is waiting for us to send the end-of-file command.
-
- fHandler.in.readByte(); // Block and wait until the terminate request. There shouldn't be anything else in the pipeline.
- if (fHandler.in.available() > 0)
- // There was something else waiting. Let's just clear it out to be safe.
- fHandler.in.skip(fHandler.in.available());
- }
- } catch (CommandException e) {
- processException(e);
- }
- } finally {
- clearStream();
- }
- }
- }
-
- public void write(int b) throws IOException {
- fBuffer[fNextByte++] = (byte) b;
- if (fNextByte >= fBuffer.length)
- flushBuffer();
- }
-
- public void write(byte b[], int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0) ||
- ((off + len) > b.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return;
- }
-
- while (len > 0) {
- int move = fBuffer.length-fNextByte;
- if (len < move)
- move = len;
- System.arraycopy(b, off, fBuffer, fNextByte, move);
- len -= move;
- off += move;
- fNextByte += move;
- if (fNextByte >= fBuffer.length)
- flushBuffer();
- }
- }
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ClassHelper.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ClassHelper.java
deleted file mode 100644
index 52ef4820f..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ClassHelper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: ClassHelper.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * This class is a helper for Class accessing functions.
- * Its main function is to bypass security. This is because
- * we don't care about security for remote vm. Security is
- * handled by the IDE and compilor over there. We do what
- * we're told.
- *
- * @author richkulp
- */
-public class ClassHelper {
-
- /**
- * Constructor for ClassHelper.
- */
- private ClassHelper() {
- super();
- }
-
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- public static Object newInstance(Class targetClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
- // We want to get the default ctor, which is in the declared list. No need
- // to worry about inheritance because ctors are never virtual.
- Constructor ctor = targetClass.getDeclaredConstructor(EMPTY_CLASS_ARRAY);
- ctor.setAccessible(true);
- return ctor.newInstance(EMPTY_OBJECT_ARRAY);
- }
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionHandler.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionHandler.java
deleted file mode 100644
index d7780b913..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionHandler.java
+++ /dev/null
@@ -1,926 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: ConnectionHandler.java,v $
- * $Revision: 1.16 $ $Date: 2005/12/02 18:41:25 $
- */
-
-
-import java.io.*;
-import java.lang.reflect.Array;
-import java.net.Socket;
-import java.net.SocketException;
-import java.util.*;
-
-import org.eclipse.jem.internal.proxy.common.CommandException;
-import org.eclipse.jem.internal.proxy.common.remote.*;
-import org.eclipse.jem.internal.proxy.initParser.*;
-import org.eclipse.jem.internal.proxy.initParser.tree.NoExpressionValueException;
-
-/**
- * This handles one connection.
- */
-
-public class ConnectionHandler {
-
- protected Socket socket;
- final protected RemoteVMServerThread server;
- final protected Thread connectionThread;
- protected DataInputStream in;
- protected DataOutputStream out;
-
- // Kludge: Bug in Linux 1.3.xxx of JVM. Closing a socket while the socket is being read/accept will not interrupt the
- // wait. Need to timeout to the socket read/accept before the socket close will be noticed. This has been fixed
- // in Linux 1.4. So on Linux 1.3 need to put timeouts in on those sockets that can be separately closed while reading/accepting.
- static boolean LINUX_1_3 = "linux".equalsIgnoreCase(System.getProperty("os.name")) && System.getProperty("java.version","").startsWith("1.3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-
- /**
- * This may be running as a callback, in that case there is no connectionThread.
- */
- public ConnectionHandler(Socket sc, RemoteVMServerThread svr, Thread connectionThread) {
- socket = sc;
- server = svr;
- this.connectionThread = connectionThread;
-
- Integer bufSize = Integer.getInteger("proxyvm.bufsize"); //$NON-NLS-1$
- if (bufSize == null)
- bufSize = new Integer(5000);
-
- try {
- out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), bufSize.intValue()));
- in = new DataInputStream(new BufferedInputStream(socket.getInputStream(), bufSize.intValue()));
- } catch (IOException e) {
- }
-
- }
-
- /**
- * Did this construct correctly.
- * This is needed because an exception could be thrown in the ctor and
- * that's not a good thing to do.
- */
- public boolean isConnected() {
- return socket != null;
- }
-
- /**
- * Request the thread to close down.
- */
- public void close() {
- if (socket != null) {
- try {
- Socket s = socket;
- socket = null;
- s.close();
- } catch (Exception e) {
- }
- }
- }
-
- // Map of ID to expression processers that are currently being processed.
- private Map expressionProcessors = new HashMap();
-
- /**
- * Process and loop until told to stop. A callback_done will stop
- * the loop and will return a result. Otherwise null is returned.
- */
- public Object run() throws CommandException {
- Object result = null;
- boolean shutdown = false;
- boolean closeWhenDone = true;
- Commands.ValueObject valueObject = new Commands.ValueObject(); // Working value object so not continually recreated.
- InvokableValueSender valueSender = new InvokableValueSender(); // Working valuesender so not continually recreated.
- try {
- boolean doLoop = true;
-
- /**
- * Note: In the cases below you will see a lot of finally clauses that null variables out.
- * This is because this is a long running loop, and variables declared within blocks are not
- * garbage collected until the method is terminated, so these variables once set would never
- * be GC'd. The nulling at the end of the case makes sure that any of those objects set are
- * now available for garbage collection when necessary.
- */
- while(doLoop && isConnected()) {
- byte cmd = 0;
- try {
- if (LINUX_1_3)
- socket.setSoTimeout(1000); // Linux 1.3 bug, see comment on LINUX_1_3
- cmd = in.readByte();
- if (LINUX_1_3 && isConnected())
- socket.setSoTimeout(0); // Linux 1.3 bug, see comment on LINUX_1_3
- } catch (InterruptedIOException e) {
- continue; // Timeout, try again
- }
- switch (cmd) {
- case Commands.QUIT_CONNECTION:
- doLoop = false;
- break; // Close this connection
-
- case Commands.TERMINATE_SERVER:
- doLoop = false;
- shutdown = true; // Shutdown everything
- break;
-
- case Commands.GET_CLASS:
- String className = in.readUTF();
- Class aClass = null;
- Class superClass = null;
- String superClassName = null;
- boolean added = false;
- try {
- aClass = Class.forName(className); // Turns out using JNI format for array type will work fine.
-
- added = server.getIdentityID(aClass, valueObject);
- boolean isInterface = aClass.isInterface();
- boolean isAbstract = java.lang.reflect.Modifier.isAbstract(aClass.getModifiers());
- superClass = aClass.getSuperclass();
- superClassName = (superClass != null) ? superClass.getName() : ""; //$NON-NLS-1$
- out.writeByte(Commands.GET_CLASS_RETURN);
- out.writeInt(valueObject.objectID);
- out.writeBoolean(isInterface);
- out.writeBoolean(isAbstract);
- out.writeUTF(superClassName);
- out.flush();
- } catch (ClassNotFoundException e) {
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.GET_CLASS_NOT_FOUND, valueObject);
- } catch (ExceptionInInitializerError e) {
- sendException(e.getException(), valueObject, out);
- } catch (LinkageError e) {
- sendException(e, valueObject, out);
- } catch (Throwable e) {
- // Something bad, did we add a class? If we did remove it from the table.
- if (added)
- server.removeObject(server.getObject(valueObject.objectID));
- throw e;
- } finally {
- // clear out for GC to work.
- className = null;
- aClass = null;
- superClass = null;
- superClassName = null;
- valueObject.set();
- }
- break;
-
- case Commands.GET_CLASS_FROM_ID:
- int classID = in.readInt();
- try {
- aClass = (Class) server.getObject(classID);
- boolean isInterface = aClass.isInterface();
- boolean isAbstract = java.lang.reflect.Modifier.isAbstract(aClass.getModifiers());
- superClass = aClass.getSuperclass();
- superClassName = (superClass != null) ? superClass.getName() : ""; //$NON-NLS-1$
- out.writeByte(Commands.GET_CLASS_ID_RETURN);
- out.writeUTF(aClass.getName());
- out.writeBoolean(isInterface);
- out.writeBoolean(isAbstract);
- out.writeUTF(superClassName);
- out.flush();
- } catch (ClassCastException e) {
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
- } finally {
- // clear out for GC to work.
- aClass = null;
- superClass = null;
- superClassName = null;
- valueObject.set();
- }
- break;
-
- case Commands.GET_OBJECT_DATA:
- int objectID = in.readInt();
- Object anObject = null;
- try {
- anObject = server.getObject(objectID);
- valueObject.setObjectID(objectID, server.getIdentityID(anObject.getClass()));
- Commands.writeValue(out, valueObject, true);
- } catch (ClassCastException e) {
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
- } finally {
- anObject = null; // Clear out for GC to work
- valueObject.set();
- }
- break;
-
- case Commands.RELEASE_OBJECT:
- int id = in.readInt();
- server.removeObject(server.getObject(id));
- break;
-
- case Commands.NEW_INIT_STRING:
- classID = in.readInt(); // ID Of class to do new upon.
- String initString = in.readUTF(); // The init string.
- Object newValue = null;
- Class theClass = null;
- try {
- theClass = (Class) server.getObject(classID);
- if (theClass == null) {
- // The class wasn't found. So imply ClassNotFound exception.
- throw new ClassNotFoundException();
- }
-
- InitializationStringParser parser = null;
- try {
- parser = InitializationStringParser.createParser(initString);
- newValue = parser.evaluate();
- boolean primitive = parser.isPrimitive();
- // If expected class is Void.TYPE, that means don't test the type of the result
- // to verify if correct type, just return what it really is.
- if (theClass != Void.TYPE && primitive != theClass.isPrimitive()) {
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
- continue; // Goto next command.
- }
- if (primitive) {
- try {
- // Need to do special tests for compatibility and assignment.
- sendObject(newValue, classID != Commands.VOID_TYPE ? classID : server.getIdentityID(parser.getExpectedType()), valueObject, out, true); // This will make sure it goes out as the correct primitive type
- } catch (ClassCastException e) {
- // The returned type is not of the correct type for what is expected.
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
- continue; // Goto next command
- }
- } else {
- if (newValue != null) {
- // Test to see if they are compatible. (Null can be assigned to any object,
- // so that is why it was tested out above).
- // If expected class is Void.TYPE, that means don't test the type of the result
- // to verify if correct type, just return what it really is.
- if (theClass != Void.TYPE && !theClass.isInstance(newValue)) {
- // The returned type is not of the correct type for what is expected.
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
- continue; // Goto next command
- }
- }
- sendObject(newValue, NOT_A_PRIMITIVE, valueObject, out, true); // Send out as an object.
- }
- } catch (InitializationStringEvaluationException e) {
- if (e instanceof EvaluationException) {
- // Want to return the real exception.
- sendException(e.getOriginalException(), valueObject, out);
- } else {
- // Couldn't be evaluated, return an error for this.
- setExceptionIntoValue(e.getOriginalException(), valueObject);
- Commands.sendErrorCommand(out, Commands.CANNOT_EVALUATE_STRING, valueObject);
- }
- } finally {
- parser = null; // Clear out for GC to work
- }
- } catch (Throwable e) {
- sendException(e, valueObject, out);
- } finally {
- // Clear out for GC to work
- initString = null;
- theClass = null;
- newValue = null;
- valueObject.set();
- }
- break;
-
- case Commands.INVOKE:
- Object target = null;
- Object[] parms = null;
- Class returnType = null;
- java.lang.reflect.Method aMethod = null;
- try {
- int methodID = in.readInt(); // ID of method to invoke
- aMethod = (java.lang.reflect.Method) server.getObject(methodID); // Method to invoke
- Commands.readValue(in, valueObject);
- target = getInvokableObject(valueObject);
- Commands.readValue(in, valueObject);
- if (valueObject.type == Commands.ARRAY_IDS) {
- // It is an array containing IDs, as it normally would be.
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- parms = (Object[]) valueSender.getArray();
- } else {
- // It is all objects or null, so it should be an Object[] or null. If not, then this is an error.
- parms = (Object[]) valueObject.anObject;
- }
-
- if (!aMethod.isAccessible())
- aMethod.setAccessible(true); // We will allow all to occur. Let access control be handled by IDE and compiler.
- newValue = aMethod.invoke(target, parms);
- returnType = aMethod.getReturnType();
- if (returnType.isPrimitive()) {
- int returnTypeID = server.getIdentityID(returnType);
- // Need to tell sendObject the correct primitive type.
- sendObject(newValue, returnTypeID, valueObject, out, true);
-
- } else {
- sendObject(newValue, NOT_A_PRIMITIVE, valueObject, out, true); // Just send the object back. sendObject knows how to iterpret the type
- }
- } catch (CommandException e) {
- throw e; // Throw it again. These we don't want to come up as an exception proxy. These should end the thread.
- } catch (java.lang.reflect.InvocationTargetException e) {
- // This is a wrappered exception. Return the wrappered one so it looks like
- // it was the real one. (Sometimes the method being invoked is on a java.lang.reflect.Constructor.newInstance,
- // which in turn is an InvocationTargetException, so we will go until we don't have an InvocationTargetException.
- Throwable t = e;
- do {
- t = ((java.lang.reflect.InvocationTargetException) t).getTargetException();
- } while (t instanceof java.lang.reflect.InvocationTargetException);
- sendException(t, valueObject, out);
- } catch (Throwable e) {
- sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
- } finally {
- // Clear out for GC to work
- valueObject.set();
- parms = null;
- target = null;
- aMethod = null;
- returnType = null;
- newValue = null;
- valueSender.clear();
- }
- break;
-
- case Commands.INVOKE_WITH_METHOD_PASSED:
- aClass = null;
- String methodName = null;
- Class[] parmTypes = null;
- target = null;
- parms = null;
- returnType = null;
- aMethod = null;
-
- try {
- Commands.readValue(in, valueObject);
- aClass = (Class) getInvokableObject(valueObject); // The class that has the method.
- methodName = in.readUTF();
- Commands.readValue(in, valueObject);
- if (valueObject.type == Commands.ARRAY_IDS) {
- // It is an array containing IDs, as it normally would be.
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- parmTypes = (Class[]) valueSender.getArray();
- } else {
- // It null, so it should be an null. If not, then this is an error.
- parmTypes = null;
- }
- aMethod = aClass.getMethod(methodName, parmTypes);
-
- // Now we get the info for the invocation of the method and execute it.
- Commands.readValue(in, valueObject);
- target = getInvokableObject(valueObject);
- Commands.readValue(in, valueObject);
- if (valueObject.type == Commands.ARRAY_IDS) {
- // It is an array containing IDs, as it normally would be.
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- parms = (Object[]) valueSender.getArray();
- } else {
- // It is all objects or null, so it should be an Object[] or null. If not, then this is an error.
- parms = (Object[]) valueObject.anObject;
- }
-
- if (!aMethod.isAccessible())
- aMethod.setAccessible(true); // We will allow all to occur. Let access control be handled by IDE and compiler.
- newValue = aMethod.invoke(target, parms);
- returnType = aMethod.getReturnType();
- if (returnType.isPrimitive()) {
- int returnTypeID = server.getIdentityID(returnType);
- // Need to tell sendObject the correct primitive type.
- sendObject(newValue, returnTypeID, valueObject, out, true);
-
- } else {
- sendObject(newValue, NOT_A_PRIMITIVE, valueObject, out, true); // Just send the object back. sendObject knows how to iterpret the type
- }
- } catch (CommandException e) {
- throw e; // Throw it again. These we don't want to come up as an exception proxy. These should end the thread.
- } catch (java.lang.reflect.InvocationTargetException e) {
- // This is a wrappered exception. Return the wrappered one so it looks like
- // it was the real one. (Sometimes the method being invoked is on a java.lang.reflect.Constructor.newInstance,
- // which in turn is an InvocationTargetException, so we will go until we don't have an InvocationTargetException.
- Throwable t = e;
- do {
- t = ((java.lang.reflect.InvocationTargetException) t).getTargetException();
- } while (t instanceof java.lang.reflect.InvocationTargetException);
- sendException(t, valueObject, out);
-
- } catch (Throwable e) {
- sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
- } finally {
- aClass = null;
- methodName = null;
- parmTypes = null;
- // Clear out for GC to work
- valueObject.set();
- parms = null;
- target = null;
- aMethod = null;
- returnType = null;
- newValue = null;
- valueSender.clear();
- }
- break;
-
- case Commands.GET_ARRAY_CONTENTS:
- try {
- target = server.getObject(in.readInt()); // Array to get the ids for.
- valueObject.setArrayIDS(new ArrayContentsRetriever(target), Array.getLength(target), Commands.OBJECT_CLASS);
- Commands.writeValue(out, valueObject, true); // Write it back as a value command.
- } catch (CommandException e) {
- throw e; // Throw it again. These we don't want to come up as an exception proxy. These should end the thread.
- } catch (Throwable e) {
- sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
- } finally {
- target = null;
- valueObject.set();
- }
- break;
-
- case Commands.CALLBACK_DONE:
- try {
- if (connectionThread != null) {
- valueObject.set();
- Commands.sendErrorCommand(out, Commands.UNKNOWN_COMMAND_SENT, valueObject);
- } else {
- try {
- Commands.readBackValue(in, valueObject, Commands.NO_TYPE_CHECK);
- if (valueObject.type == Commands.ARRAY_IDS) {
- // It is an array containing IDs, as it normally would be.
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- result = valueSender.getArray();
- } else {
- result = getInvokableObject(valueObject);
- }
- doLoop = false; // We need to terminate and return result
- closeWhenDone = false; // Don't close, we will continue.
- } catch (CommandErrorException e) {
- // There was an command error on the other side. This means
- // connection still good, but don't continue the callback processing.
- doLoop = false; // We need to terminate and return result
- closeWhenDone = false; // Don't close, we will continue.
- throw e; // Let it go on out.
- }
- }
- } finally {
- valueObject.set();
- valueSender.clear();
- }
- break;
-
- case Commands.ERROR:
- try {
- // Got an error command. Don't know what to do but read the
- // value and simply print it out.
- Commands.readValue(in, valueObject);
- result = getInvokableObject(valueObject);
- System.out.println("Error sent to server: Result=" + result); //$NON-NLS-1$
- } finally {
- valueObject.set();
- }
- break;
-
- case Commands.EXPRESSION_TREE_COMMAND:
- try {
- processExpressionCommand(valueObject, valueSender);
- } finally {
- valueObject.set();
- valueSender.clear();
- }
- break;
-
- default:
- // Unknown command. We don't know how long it is, so we need to shut the connection down.
- System.err.println("Error: Invalid cmd send to server: Cmd=" + cmd); //$NON-NLS-1$
- doLoop = false;
- closeWhenDone = true;
- break;
- }
- }
- } catch (EOFException e) {
- // This is ok. It means that the connection on the other side was terminated.
- // So just accept this and go down.
- } catch (CommandException e) {
- throw e;
- } catch (SocketException e) {
- if (socket != null)
- throw new UnexpectedExceptionCommandException(false, e); // socket null means a valid close request
- } catch (Throwable e) {
- e.printStackTrace();
- } finally {
- if (closeWhenDone) {
- try {
- for (Iterator itr = expressionProcessors.values().iterator(); itr.hasNext();) {
- ExpressionProcesserController exp = (ExpressionProcesserController) itr.next();
- exp.close();
- }
- } finally {
- expressionProcessors.clear();
- }
-
- if (in != null)
- try {
- in.close();
- } catch (Exception e) {
- }
- in = null;
- if (out != null)
- try {
- out.close();
- } catch (Exception e) {
- }
- out = null;
- close();
- }
- }
-
- if (closeWhenDone && connectionThread != null)
- server.removeConnectionThread(connectionThread);
- if (shutdown)
- server.requestShutdown();
-
- return result;
- }
-
- // A retriever is what handles the array get contents.
- private class ArrayContentsRetriever implements Commands.ValueRetrieve {
- int index=0;
- Object array;
- int length;
- int componentType;
- Commands.ValueObject worker = new Commands.ValueObject();
-
-
- public ArrayContentsRetriever(Object anArray) {
- array = anArray;
- length = Array.getLength(anArray);
- if (anArray.getClass().getComponentType().isPrimitive()) {
- componentType = server.getIdentityID(anArray.getClass().getComponentType());
- } else
- componentType = NOT_A_PRIMITIVE;
- }
-
- public Commands.ValueObject nextValue() {
- fillInValue(Array.get(array, index++), componentType, worker);
- return worker;
- }
- };
-
-
- private void processExpressionCommand(Commands.ValueObject valueObject, InvokableValueSender valueSender) throws IOException, CommandException {
- Integer expressionID = new Integer(in.readInt());
- byte cmdType = in.readByte();
- ExpressionProcesserController exp = null;
- switch (cmdType) {
- case ExpressionCommands.START_EXPRESSION_TREE_PROCESSING:
- byte trace = in.readByte();
- if (trace == ExpressionCommands.TRACE_DEFAULT)
- exp = new ExpressionProcesserController(server, this);
- else
- exp = new ExpressionProcesserController(server, this, trace == ExpressionCommands.TRACE_ON);
- expressionProcessors.put(expressionID, exp);
- break;
- case ExpressionCommands.TRANSFER_EXPRESSION_REQUEST:
- exp = (ExpressionProcesserController) expressionProcessors.remove(expressionID);
- sendObject(exp, NOT_A_PRIMITIVE, valueObject, out, true);
- break;
- case ExpressionCommands.RESUME_EXPRESSION_REQUEST:
- Commands.readValue(in, valueObject);
- exp = (ExpressionProcesserController) getInvokableObject(valueObject);
- expressionProcessors.put(expressionID, exp);
- break;
- case ExpressionCommands.PUSH_EXPRESSION:
- exp = (ExpressionProcesserController) expressionProcessors.get(expressionID);
- exp.process(in);
- break;
- case ExpressionCommands.SYNC_REQUEST:
- boolean haveProxies = in.readBoolean(); // See if we expression proxy ids that need to be resolved
- if (haveProxies) {
- Commands.readValue(in, valueObject);
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- }
-
- exp = (ExpressionProcesserController) expressionProcessors.get(expressionID);
- if (haveProxies)
- sendExpressionProxyResolutions(valueObject, (int[]) valueSender.getArray(), exp);
- if (exp.noErrors()) {
- valueObject.set(true); // Mark that all is good.
- Commands.writeValue(out, valueObject, true, true);
- } else {
- processExpressionError(exp, valueObject);
- }
- break;
- case ExpressionCommands.PULL_VALUE_REQUEST:
- haveProxies = in.readBoolean(); // See if we expression proxy ids that need to be resolved
- if (haveProxies) {
- Commands.readValue(in, valueObject);
- valueSender.initialize(valueObject);
- Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
- }
-
- exp = (ExpressionProcesserController) expressionProcessors.get(expressionID);
- if (haveProxies)
- sendExpressionProxyResolutions(valueObject, (int[]) valueSender.getArray(), exp);
- if (exp.noErrors()) {
- try {
- Object[] pulledValue = exp.pullValue();
- // Send back the command code for pull value. Don't flush. We will flush when all done.
- if (((Class) pulledValue[1]).isPrimitive()) {
- int returnTypeID = server.getIdentityID(pulledValue[1]);
- // Need to tell sendObject the correct primitive type.
- sendObject(pulledValue[0], returnTypeID, valueObject, out, true, true);
-
- } else {
- sendObject(pulledValue[0], NOT_A_PRIMITIVE, valueObject, out, true, true); // Just send the object back. sendObject knows how to iterpret the type
- }
- } catch (NoExpressionValueException e) {
- sendNoValueErrorCommand(exp, valueObject);
- }
- } else
- processExpressionError(exp, valueObject);
- break;
- case ExpressionCommands.END_EXPRESSION_TREE_PROCESSING:
- exp = (ExpressionProcesserController) expressionProcessors.remove(expressionID);
- exp.close();
- break;
- }
- }
-
- /*
- * @param is
- * @param exp
- *
- * @since 1.1.0
- */
- private void sendExpressionProxyResolutions(Commands.ValueObject valueObject, final int[] proxyIDs, final ExpressionProcesserController exp) throws CommandException {
- class ExpressionProxyRetriever implements Commands.ValueRetrieve {
- int index = 0;
- Object[] proxyResolution = new Object[2];
- Commands.ValueObject worker = new Commands.ValueObject();
-
- public Commands.ValueObject nextValue() {
- int proxyID = proxyIDs[index++];
- if (exp.pullExpressionProxyValue(proxyID, proxyResolution)) {
- if (proxyResolution[1] != Void.TYPE) {
- if (((Class) proxyResolution[1]).isPrimitive()) {
- int returnTypeID = server.getIdentityID(proxyResolution[1]);
- // Need to tell worker the correct primitive type.
- fillInValue(proxyResolution[0], returnTypeID, worker);
- } else {
- fillInValue(proxyResolution[0], NOT_A_PRIMITIVE, worker);
- }
- } else
- worker.setFlag(ExpressionCommands.EXPRESSIONPROXY_VOIDTYPE); // It was resolved, but to not set due to void type of expression.
- } else
- worker.setFlag(ExpressionCommands.EXPRESSIONPROXY_NOTRESOLVED); // It wasn't resolved.
-
- return worker;
- }
- };
-
- valueObject.setArrayIDS(new ExpressionProxyRetriever(), proxyIDs.length, Commands.OBJECT_CLASS);
- Commands.writeValue(out, valueObject, true, false); // Write it back as a value command.
-
- }
-
- private void processExpressionError(ExpressionProcesserController exp, Commands.ValueObject valueObject) throws CommandException {
- if (exp.isNoExpressionValue()) {
- sendNoValueErrorCommand(exp, valueObject);
- } else
- sendException(exp.getErrorThrowable(), valueObject, out);
- }
-
- /*
- * @param exp
- * @param valueObject
- * @throws CommandException
- *
- * @since 1.1.0
- */
- private void sendNoValueErrorCommand(ExpressionProcesserController exp, Commands.ValueObject valueObject) throws CommandException {
- setExceptionIntoValue(exp.getErrorThrowable(), valueObject);
- Commands.sendErrorCommand(out, ExpressionCommands.EXPRESSION_NOEXPRESSIONVALUE_EXCEPTION, valueObject);
- }
-
-protected static final int NOT_A_PRIMITIVE = Commands.NOT_AN_ID;
-protected static final int SEND_AS_IS = -2; // This means sends as an object not as an id.
-
-public static final int CLASS_ADDED = 1;
-public static final int OBJECT_ADDED = 2;
-public int fillInValue(Object object, int primitiveTypeID, Commands.ValueObject valueObject) {
- int added = 0;
- if (object == null) {
- valueObject.set();
- } else {
- int classID = 0;
- if (primitiveTypeID != NOT_A_PRIMITIVE && primitiveTypeID != SEND_AS_IS) {
- classID = primitiveTypeID; // The object is really supposed to be a primitive of this type
- switch (classID) {
- case Commands.BOOLEAN_TYPE:
- valueObject.set(((Boolean) object).booleanValue());
- break;
- case Commands.INTEGER_TYPE:
- if (object instanceof Character)
- valueObject.set((int) ((Character) object).charValue()); // Because char can be widened to an int
- else
- valueObject.set(((Number) object).intValue());
- break;
- case Commands.BYTE_TYPE:
- valueObject.set(((Number) object).byteValue());
- break;
- case Commands.CHARACTER_TYPE:
- valueObject.set(((Character) object).charValue());
- break;
- case Commands.DOUBLE_TYPE:
- if (object instanceof Character)
- valueObject.set((double) ((Character) object).charValue()); // Because char can be widened to a double
- else
- valueObject.set(((Number) object).doubleValue());
- break;
- case Commands.FLOAT_TYPE:
- if (object instanceof Character)
- valueObject.set((float) ((Character) object).charValue()); // Because char can be widened to a float
- else
- valueObject.set(((Number) object).floatValue());
- break;
- case Commands.SHORT_TYPE:
- valueObject.set(((Number) object).shortValue());
- break;
- case Commands.LONG_TYPE:
- if (object instanceof Character)
- valueObject.set((long) ((Character) object).charValue()); // Because char can be widened to a long
- else
- valueObject.set(((Number) object).longValue());
- break;
- }
- } else {
- // It's not a primitive.
- boolean addObject = false, addClass = false;
- Class objClass = object.getClass();
- classID = server.getIdentityID(objClass);
- if (classID == RemoteVMServerThread.ID_NOT_FOUND) {
- Commands.ValueObject classValue = new Commands.ValueObject();
- addClass = server.getIdentityID(objClass, classValue);
- if (addClass)
- added |= CLASS_ADDED;
- classID = classValue.objectID;
- }
-
- switch (classID) {
- case Commands.BYTE_CLASS:
- valueObject.set((Byte) object);
- break;
- case Commands.CHARACTER_CLASS:
- valueObject.set((Character) object);
- break;
- case Commands.DOUBLE_CLASS:
- valueObject.set((Double) object);
- break;
- case Commands.FLOAT_CLASS:
- valueObject.set((Float) object);
- break;
- case Commands.INTEGER_CLASS:
- valueObject.set((Integer) object);
- break;
- case Commands.LONG_CLASS:
- valueObject.set((Long) object);
- break;
- case Commands.SHORT_CLASS:
- valueObject.set((Short) object);
- break;
- case Commands.BOOLEAN_CLASS:
- valueObject.set((Boolean) object);
- break;
- case Commands.STRING_CLASS:
- valueObject.set((String) object);
- break;
- case Commands.BIG_DECIMAL_CLASS:
- valueObject.set(object, Commands.BIG_DECIMAL_CLASS);
- break;
- case Commands.BIG_INTEGER_CLASS:
- valueObject.set(object, Commands.BIG_INTEGER_CLASS);
- break;
- default:
- if (primitiveTypeID != SEND_AS_IS) {
- addObject = server.getIdentityID(object, valueObject);
- if (addObject) {
- added |= OBJECT_ADDED;
- valueObject.setObjectID(valueObject.objectID, classID);
- } else
- valueObject.setObjectID(valueObject.objectID);
- } else
- valueObject.set(object, classID);
- break;
- }
- }
- }
-
- return added;
-}
-
-public void sendObject(Object object, int primitiveTypeID, Commands.ValueObject valueObject, DataOutputStream out, boolean writeAsCommand) throws CommandException {
- sendObject(object, primitiveTypeID, valueObject, out, writeAsCommand, writeAsCommand);
-}
-public void sendObject(Object object, int primitiveTypeID, Commands.ValueObject valueObject, DataOutputStream out, boolean writeAsCommand, boolean flush) throws CommandException {
- int added = fillInValue(object, primitiveTypeID, valueObject);
- boolean sent = false;
- try {
- Commands.writeValue(out, valueObject, writeAsCommand, flush); // Write it back as a value command.
- sent = true;
- } finally {
- if (!sent) {
- // Ending due to some problem, so clean up any added objects from the id table.
- if ((added & OBJECT_ADDED) != 0)
- server.removeObject(valueObject.objectID);
- if ((added & CLASS_ADDED) != 0)
- server.removeObject(valueObject.classID);
- }
- }
-}
-
-
- public void sendException(Throwable e, Commands.ValueObject value, DataOutputStream out) throws CommandException {
- // Exception ocurred, return a value command with the exception within it.
- setExceptionIntoValue(e, value);
- Commands.sendErrorCommand(out, Commands.THROWABLE_SENT, value);
- }
-
- public void setExceptionIntoValue(Throwable e, Commands.ValueObject value) {
- server.getIdentityID(e, value); // It should always create it so we don't need to know.
- int eID = value.objectID;
- Class eClass = e.getClass();
- server.getIdentityID(eClass, value);
- int eClassID = value.objectID;
- value.setException(eID, eClassID);
- }
-
- /**
- * From the valueObject, get an Object that is invokable (i.e. can be the target of an invoke, or one of its parms).
- * If it is an array type, the a ValueSender is returned. The invoker needs to then cast this
- * to a ValueSender and call the readArray routine.
- */
- public Object getInvokableObject(final Commands.ValueObject value) {
- switch (value.type) {
- case Commands.NEW_OBJECT_ID:
- case Commands.OBJECT_ID:
- // These need to have access to the server to get the real object
- return server.getObject(value.objectID);
- default:
- // These have all the info needed within the value object itself, so ask it.
- return value.getAsObject();
- }
- }
-
- // Helper class for getting an array.
- private class InvokableValueSender implements Commands.ValueSender {
- int index = 0;
- Object array;
-
- public InvokableValueSender() {
- }
-
- public InvokableValueSender(Commands.ValueObject arrayHeader) {
- initialize(arrayHeader);
- }
-
- public void initialize(Commands.ValueObject arrayHeader) {
- index = 0;
- Class arrayType = (Class) server.getObject(arrayHeader.classID);
- array = java.lang.reflect.Array.newInstance(arrayType, arrayHeader.anInt);
- }
-
- public void clear() {
- array = null;
- index = 0;
- }
-
- public Object getArray() {
- return array;
- }
-
- // A new value is being sent to the array
- public void sendValue(Commands.ValueObject value) {
- java.lang.reflect.Array.set(array, index++, getInvokableObject(value)); // add it to the array
- }
-
- // The next entry is an array too!
- public Commands.ValueSender nestedArray(Commands.ValueObject arrayHeader) {
- InvokableValueSender sender = new InvokableValueSender(arrayHeader);
- // Take the newly created array and put it into the current array.
- java.lang.reflect.Array.set(array, index++, sender.getArray());
- return sender;
- }
- }
-
-}
-
-
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionThread.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionThread.java
deleted file mode 100644
index c472123da..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ConnectionThread.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: ConnectionThread.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-
-import java.net.Socket;
-
-import org.eclipse.jem.internal.proxy.common.CommandException;
-/**
- * This is a thread to handle one connection.
- */
-
-public class ConnectionThread extends Thread {
-
- final protected ConnectionHandler connectionHandler;
-
- public ConnectionThread(Socket sc, RemoteVMServerThread svr, String name) {
- super(name);
-
- connectionHandler = new ConnectionHandler(sc, svr, this);
- }
-
- /**
- * Request the thread to close down.
- */
- public void close() {
- try {
- connectionHandler.close();
- } catch (Exception e) {
- }
- }
-
- public void run() {
- try {
- connectionHandler.run();
- } catch (CommandException e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ExpressionProcesserController.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ExpressionProcesserController.java
deleted file mode 100644
index a6797d047..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/ExpressionProcesserController.java
+++ /dev/null
@@ -1,809 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * $RCSfile: ExpressionProcesserController.java,v $
- * $Revision: 1.12 $ $Date: 2005/08/24 20:39:08 $
- */
-package org.eclipse.jem.internal.proxy.vm.remote;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.jem.internal.proxy.common.*;
-import org.eclipse.jem.internal.proxy.common.remote.Commands;
-import org.eclipse.jem.internal.proxy.common.remote.ExpressionCommands;
-import org.eclipse.jem.internal.proxy.initParser.tree.*;
-
-
-/**
- * This processes the commands for expression processing and sends them over
- * to the common expression processer.
- *
- * This will be instantiated on the start of an expression. And then
- * each expression request from the IDE will be sent into here. The
- * reason this guy doesn't hold onto the connection and process the
- * entire expression is because we need to return to the connection
- * handler to keep the connection live (there is timeouts and stuff
- * in there that we don't want to duplicate here).
- * <p>
- * If there are any expression processing errors (versus hard io errors) we
- * will save up the error but don't do any more processing other than to make
- * sure we read the complete subcommand. This is so that the inputstream is left
- * in a valid state without standed data.
- * <p>
- * The at the sync point (either get value or sync subcommand) we will send back
- * the error.
- *
- * @since 1.0.0
- */
-public class ExpressionProcesserController {
-
-
- protected final RemoteVMServerThread server;
- protected final ConnectionHandler connHandler;
- protected final ExpressionProcesser exp;
- protected Commands.ValueObject workerValue = new Commands.ValueObject(); // A worker value object so we don't need to keep creating them and releasing them.
- private ClassLoader classLoader;
-
- /**
- * Create with a default expression processer and use default flag for trace.
- * @param server
- *
- * @since 1.0.0
- */
- public ExpressionProcesserController(RemoteVMServerThread server, ConnectionHandler connHandler) {
- this(server, connHandler, new ExpressionProcesser(Boolean.getBoolean(ExpressionCommands.EXPRESSIONTRACE), Long.getLong(ExpressionCommands.EXPRESSIONTRACE_TIMER_THRESHOLD, -1L).longValue()));
- }
-
- /**
- * Construct with a default expression processer.
- * @param server
- * @param connHandler
- * @param trace
- *
- * @since 1.1.0
- */
- public ExpressionProcesserController(RemoteVMServerThread server, ConnectionHandler connHandler, boolean trace) {
- this(server, connHandler, new ExpressionProcesser(trace, Long.getLong(ExpressionCommands.EXPRESSIONTRACE_TIMER_THRESHOLD, -1L).longValue()));
- }
-
- /**
- * Create from a subclass with a given expression processer.
- *
- * @param server
- * @param exp
- *
- * @since 1.0.0
- */
- protected ExpressionProcesserController(RemoteVMServerThread server, ConnectionHandler connHandler, ExpressionProcesser exp) {
- this.server = server;
- this.connHandler = connHandler;
- this.exp = exp;
- }
-
- /**
- * Set the class loader to use for finding classes. If never set, or if <code>null</code>, then
- * <code>Class.forName</code> will be used.
- *
- * @param classLoader
- *
- * @since 1.0.0
- */
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- /*
- * Array of primitive type names. Used to look up primtive types in primitive types array.
- *
- * @since 1.0.0
- */
- private static final List PRIMITIVE_NAMES = Arrays.asList(new String[] {"byte", "char", "short", "int", "long", "float", "double"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- private static final Class[] PRIMITIVE_TYPES = new Class[] {Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
- /**
- * Load the class given the name. If not found, return null.
- *
- * @param className
- * @return
- *
- * @since 1.0.0
- */
- protected Class loadClass(String className) throws ClassNotFoundException {
- if (className == null)
- return null;
- else if (className.endsWith("[]")) { //$NON-NLS-1$
- // We have an array request instead. This is trickier.
- return loadClass(MapTypes.getJNIFormatName(className));
- } else {
- int primIndex = PRIMITIVE_NAMES.indexOf(className);
- if (primIndex >= 0)
- return PRIMITIVE_TYPES[primIndex];
- else if (classLoader == null) {
- return Class.forName(className);
- } else {
- return classLoader.loadClass(className);
- }
- }
- }
-
- /**
- * Now process the input stream. If either throws occurs, this is a hard error and we must terminate
- * the entire connection. The input stream is in an unknown state.
- *
- * @param in The input stream to get the data for the current sub-command.
- *
- * @throws CommandException
- * @throws IOException
- * @since 1.0.0
- */
- public void process(DataInputStream in) throws CommandException, IOException {
- // In the following subcommand processing, we always read the entire subcommand from the stream.
- // This is so that any errors during processing will not mess up the stream with unread data.
- //
- // Then we check if an error has occurred in the past. If it has, we simply break. This is because
- // once an error occurred we don't want to continue wasting time evaluating, however we need to make
- // sure that the stream is read completely so that we don't have a corrupted input stream. That way
- // when all is done we can return the error and still have a valid connection socket.
- byte subcommand = in.readByte();
- try {
- switch (subcommand) {
- case InternalExpressionTypes.PUSH_TO_PROXY_EXPRESSION_VALUE:
- // Getting a proxy push. The value is sent as valueObject, so use that to read it in.
- Commands.readValue(in, workerValue);
- Object value = connHandler.getInvokableObject(workerValue);
- if (value == null)
- exp.pushExpression(null, MethodHelper.NULL_TYPE);
- else if (workerValue.isPrimitive())
- exp.pushExpression(value, workerValue.getPrimitiveType());
- else
- exp.pushExpression(value, value.getClass());
- break;
-
- case InternalExpressionTypes.CAST_EXPRESSION_VALUE:
- // Get a cast request. The type is sent as valueObject.
- Commands.readValue(in, workerValue);
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushCast(classValue);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.INSTANCEOF_EXPRESSION_VALUE:
- // Get a instanceof request. The type is sent as valueObject.
- Commands.readValue(in, workerValue);
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushInstanceof(classValue);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.INFIX_EXPRESSION_VALUE:
- // Get an infix request. The operator and operand type are sent as bytes.
- byte infix_operator = in.readByte();
- byte infix_operandType = in.readByte();
- exp.pushInfix(InfixOperator.get(infix_operator), InternalInfixOperandType.get(infix_operandType));
- break;
-
- case InternalExpressionTypes.PREFIX_EXPRESSION_VALUE:
- // Get a prefix request. The operator is sent as byte.
- byte prefix_operandType = in.readByte();
- exp.pushPrefix(PrefixOperator.get(prefix_operandType));
- break;
-
- case InternalExpressionTypes.ARRAY_ACCESS_EXPRESSION_VALUE:
- // Get an array access request. The index cound is sent as int.
- int arrayAccess_Indexcount = in.readInt();
- exp.pushArrayAccess(arrayAccess_Indexcount);
- break;
-
- case InternalExpressionTypes.ARRAY_CREATION_EXPRESSION_VALUE:
- // Get an array creation request. The type is sent as valueObject, followed by int dimension count.
- Commands.readValue(in, workerValue);
- int arrayCreation_dimCount = in.readInt();
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushArrayCreation(classValue, arrayCreation_dimCount);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.ARRAY_INITIALIZER_EXPRESSION_VALUE:
- // Get an array initializer request. The type is sent as valueObject, followed by int expression count.
- Commands.readValue(in, workerValue);
- int stripCount = in.readInt();
- int arrayInitializer_expressionCount = in.readInt();
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushArrayInitializer(classValue, stripCount, arrayInitializer_expressionCount);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.CLASS_INSTANCE_CREATION_EXPRESSION_VALUE:
- // Get a class instance creation request. The type is sent as valueObject, followed by int argument count.
- Commands.readValue(in, workerValue);
- int newInstance_argCount = in.readInt();
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushClassInstanceCreation(classValue, newInstance_argCount);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.TYPERECEIVER_EXPRESSION_VALUE:
- // Get a type receiver request. The type is sent as valueObject.
- Commands.readValue(in, workerValue);
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushExpression(classValue, classValue);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.FIELD_ACCESS_EXPRESSION_VALUE:
- // Get a field access request. Command.ValueObject, followed by hasReceiver as boolean.
- Commands.readValue(in, workerValue);
- boolean has_fieldAccess_receiver = in.readBoolean();
- try {
- Object fieldAccess = getFieldValue(workerValue);
- exp.pushFieldAccess(fieldAccess, workerValue.getType() == Commands.STRING, has_fieldAccess_receiver);
- } catch (ClassCastException e) {
- exp.processException(e); // Let the processor know we have a stopping error.
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.METHOD_EXPRESSION_VALUE:
- // Get a method invocation request. Sent as Commands.ValueObject, followed by hasReceiver as boolean., and argCount as int.
- Commands.readValue(in, workerValue);
- boolean has_method_receiver = in.readBoolean();
- int method_argCount = in.readInt();
- try {
- Object method = getMethodValue(workerValue);
- exp.pushMethodInvocation(method, workerValue.getType() == Commands.STRING, has_method_receiver, method_argCount);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.CONDITIONAL_EXPRESSION_VALUE:
- // Get a conditional expression request. The expression type (ie. condition/true/false) is sent as a byte
- exp.pushConditional(InternalConditionalOperandType.get(in.readByte()));
- break;
-
- case InternalExpressionTypes.ASSIGNMENT_PROXY_EXPRESSION_VALUE:
- // Get an assignment expression request. The proxy id is sent as an int.
- int proxyid = in.readInt();
- exp.pushAssignment(new RemoteExpressionProxy(proxyid));
- break;
-
- case InternalExpressionTypes.ASSIGNMENT_EXPRESSION_VALUE:
- // Get an assignment expression request. Nothing else to read from stream.
- exp.pushAssignment();
- break;
-
- case InternalExpressionTypes.PUSH_TO_EXPRESSION_PROXY_EXPRESSION_VALUE:
- // Get a push expression proxy expression. The proxy id is sent as an int.
- // First test if a possible FailedExpressionProxy because we could of been pushing
- // a failed reflection proxy.
- proxyid = in.readInt();
- try {
- exp.getExpressionProxy(proxyid, new Object[] {null, null});
- } catch (NoExpressionValueException e1) {
- if (e1.getProxy() != null) {
- FailedRemoteExpressionProxy failure = (FailedRemoteExpressionProxy) e1.getProxy();
- exp.processException((Throwable) failure.getValue());
- break; // Don't go on, we processed it. A standard no expression value should be passed on and let following code handle it.
- }
- }
- exp.pushExpressionProxy(proxyid);
- break;
-
- case InternalExpressionTypes.BLOCK_BEGIN_EXPRESSION_VALUE:
- // Get a begin block proxy expression. The block id is sent as an int.
- exp.pushBlockBegin(in.readInt());
- break;
-
- case InternalExpressionTypes.BLOCK_BREAK_EXPRESSION_VALUE:
- // Get a break block proxy expression. The block id is sent as an int.
- exp.pushBlockBreak(in.readInt());
- break;
-
- case InternalExpressionTypes.BLOCK_END_EXPRESSION_VALUE:
- // Get a end block proxy expression. The block id is sent as an int.
- exp.pushBlockEnd(in.readInt());
- break;
-
- case InternalExpressionTypes.TRY_BEGIN_EXPRESSION_VALUE:
- // Get a try begin proxy expression. The try id is sent as an int.
- exp.pushTryBegin(in.readInt());
- break;
-
- case InternalExpressionTypes.TRY_CATCH_EXPRESSION_VALUE:
- int tryNumber = in.readInt();
- Commands.readValue(in, workerValue);
- proxyid = in.readInt();
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushTryCatchClause(tryNumber, classValue, proxyid != -1 ? new RemoteExpressionProxy(proxyid) : null);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.TRY_FINALLY_EXPRESSION_VALUE:
- // Get a try finally proxy expression. The try id is sent as an int.
- exp.pushTryFinallyClause(in.readInt());
- break;
-
- case InternalExpressionTypes.TRY_END_EXPRESSION_VALUE:
- // Get a try end proxy expression. The try id is sent as an int.
- exp.pushTryEnd(in.readInt());
- break;
-
- case InternalExpressionTypes.THROW_EXPRESSION_VALUE:
- exp.pushThrowException();
- break;
-
- case InternalExpressionTypes.RETHROW_EXPRESSION_VALUE:
- // Get a rethrow proxy expression. The try id is sent as an int.
- exp.pushTryRethrow(in.readInt());
- break;
-
- case InternalExpressionTypes.PUSH_BEANTYPE_EXPRESSIONPROXY_EXPRESSION_VALUE:
- // Get the beantype expression proxy and resolve it.
- proxyid = in.readInt();
- String typeName = Commands.readStringData(in);
- try {
- Class classValue = loadClass(typeName);
- RemoteExpressionProxy rep = new RemoteExpressionProxy(proxyid);
- rep.setProxy(classValue, Class.class);
- exp.allocateExpressionProxy(rep);
- } catch (ClassNotFoundException e) {
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(e, e.getClass());
- exp.allocateExpressionProxy(rep);
- } catch (LinkageError e) {
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(e, e.getClass());
- exp.allocateExpressionProxy(rep);
- }
- break;
-
- case InternalExpressionTypes.PUSH_METHOD_EXPRESSIONPROXY_EXPRESSION_VALUE:
- // Get the Method expression proxy and resolve it.
- // Comes over as:
- // int for proxy id for the method
- // beanTypeValue for declaring class (either beantype or expression proxy)
- // string for method name
- // int for arg count
- // beanTypeValue(s) for arg types (as many as arg count).
- proxyid = in.readInt();
- Commands.ValueObject decClassValue = Commands.readValue(in, new Commands.ValueObject());
- String methodName = Commands.readStringData(in);
- int argCount = in.readInt();
- Commands.ValueObject[] args = null;
- if (argCount > 0) {
- args = new Commands.ValueObject[argCount];
- for (int i = 0; i < argCount; i++) {
- args[i] = Commands.readValue(in, new Commands.ValueObject());
- }
- }
- Class decClass = null;
- Class[] argClasses = null;
- try {
- decClass = getBeanTypeValue(decClassValue);
- argClasses = null;
- if (argCount>0) {
- argClasses = new Class[argCount];
- for (int i = 0; i < argCount; i++) {
- argClasses[i] = getBeanTypeValue(args[i]);
- }
- }
- // Now get the method itself.
- Method m = decClass.getMethod(methodName, argClasses);
- RemoteExpressionProxy rep = new RemoteExpressionProxy(proxyid);
- rep.setProxy(m, Method.class);
- exp.allocateExpressionProxy(rep);
- } catch (FailedProxyException e) {
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(e.getCause(), e.getCause().getClass());
- exp.allocateExpressionProxy(rep);
- } catch (NoSuchMethodException e) {
- // The default trace doesn't show what method was being searched for, so recreate with that.
- StringBuffer s = new StringBuffer();
- s.append(decClass.getName());
- s.append('.');
- s.append(methodName);
- s.append('(');
- if (argClasses != null) {
- for (int i = 0; i < argClasses.length; i++) {
- if (i > 0)
- s.append(',');
- s.append(argClasses[i].getName());
- }
- }
- s.append(')');
- NoSuchMethodException ne = new NoSuchMethodException(s.toString());
- ne.setStackTrace(e.getStackTrace());
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(ne, ne.getClass());
- exp.allocateExpressionProxy(rep);
- }
- break;
-
- case InternalExpressionTypes.PUSH_FIELD_EXPRESSIONPROXY_EXPRESSION_VALUE:
- // Get the Filed expression proxy and resolve it.
- // Comes over as:
- // int for proxy id for the field
- // beanTypeValue for declaring class (either beantype or expression proxy)
- // string for field name
- proxyid = in.readInt();
- decClassValue = Commands.readValue(in, new Commands.ValueObject());
- String fieldName = Commands.readStringData(in);
- try {
- decClass = getBeanTypeValue(decClassValue);
- // Now get the field itself.
- Field f = decClass.getField(fieldName);
- RemoteExpressionProxy rep = new RemoteExpressionProxy(proxyid);
- rep.setProxy(f, Method.class);
- exp.allocateExpressionProxy(rep);
- } catch (FailedProxyException e) {
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(e.getCause(), e.getCause().getClass());
- exp.allocateExpressionProxy(rep);
- } catch (NoSuchFieldException e) {
- FailedRemoteExpressionProxy rep = new FailedRemoteExpressionProxy(proxyid);
- rep.setProxy(e, e.getClass());
- exp.allocateExpressionProxy(rep);
- }
- break;
-
- case InternalExpressionTypes.IF_TEST_EXPRESSION_VALUE:
- // Get a if test expression request.
- exp.pushIfElse();
- break;
-
- case InternalExpressionTypes.IF_ELSE_EXPRESSION_VALUE:
- // Get a if/else expression clause request. The clause type (ie. true/false) is sent as a byte
- exp.pushIfElse(InternalIfElseOperandType.get(in.readByte()));
- break;
-
- case InternalExpressionTypes.NEW_INSTANCE_VALUE:
- // Get a new instance from string.
- String initString = Commands.readStringData(in);
- workerValue = Commands.readValue(in, new Commands.ValueObject());
- try {
- Class classValue = getBeanTypeValue(workerValue);
- exp.pushNewInstanceFromString(initString, classValue, classLoader);
- } catch (FailedProxyException e) {
- exp.processException(e.getCause()); // Let the processor know we have a stopping error.
- }
- break;
-
- case InternalExpressionTypes.MARK_VALUE:
- // Do a mark.
- int markID = in.readInt();
- exp.pushMark(markID);
- break;
-
- case InternalExpressionTypes.ENDMARK_VALUE:
- // Do an end mark.
- markID = in.readInt();
- boolean restore = in.readBoolean();
- exp.pushEndmark(markID, restore);
- break;
-
- case InternalExpressionTypes.SUBEXPRESSION_BEGIN_EXPRESSION_VALUE:
- // Get a begin subexpression proxy expression. The subexpression id is sent as an int.
- exp.pushSubexpressionBegin(in.readInt());
- break;
-
- case InternalExpressionTypes.SUBEXPRESSION_END_EXPRESSION_VALUE:
- // Get a end subexpression proxy expression. The subexpression id is sent as an int.
- exp.pushSubexpressionEnd(in.readInt());
- break;
-
- }
-
- } catch (RuntimeException e) {
- exp.processException(e);
- }
-
- workerValue.set(); // Clear it out so nothing being held onto.
- }
-
- /**
- * This is an exception that is thrown from the getBeanType, field, method (reflect type stuff)
- * that wrappers the real throwable that occurred during the previous reflection. This is
- * because reflection is done out of sequence with the use of the reflect value. So we need
- * to store the reflection exception in this exception and then store this exception in
- * a {@link FailedRemoteExpressionProxy}. This will then be picked up when trying to be
- * used and it will get the true exception out of the {@link Throwable#getCause()}.
- *
- * @since 1.1.0
- */
- private static class FailedProxyException extends Exception {
- /**
- * Comment for <code>serialVersionUID</code>
- *
- * @since 1.1.0
- */
- private static final long serialVersionUID = 2872325672166348923L;
-
- public FailedProxyException(Throwable realThrowable) {
- super(realThrowable);
- }
- }
-
- /**
- * Get the beantype (class) out of the value object sent in. It can handle the beantype sent or
- * as an expression proxy to a beantype expression proxy.
- *
- * @param value
- * @return
- * @throws FailedProxyException Wrappers the real throwable that caused the bean type to not be found.
- *
- * @since 1.1.0
- */
- protected Class getBeanTypeValue(Commands.ValueObject value) throws FailedProxyException {
- Object beantype = connHandler.getInvokableObject(value);
- // It is either a type directly or is an expression proxy.
- if (value.type == Commands.INT) {
- // It is an expression proxy request.
- Object[] expvalue = new Object[2];
- try {
- exp.getExpressionProxy(((Integer) beantype).intValue(), expvalue);
- beantype = expvalue[0];
- } catch (NoExpressionValueException e) {
- // See if there is a failed proxy.
- if (e.getProxy() != null) {
- FailedRemoteExpressionProxy failure = (FailedRemoteExpressionProxy) e.getProxy();
- throw new FailedProxyException((Throwable) failure.getValue());
- } else
- throw new FailedProxyException(new ClassNotFoundException()); // This shouldn't of occurred.
- }
- }
- return (Class) beantype;
- }
-
- /**
- * Get the method out of the value object sent in. It can handle the method sent or
- * as an expression proxy to a method expression proxy.
- * @param value
- * @return method if a method or string if a string or get the method if an expression proxy.
- * @throws FailedProxyException Wrappers the real Throwable that caused the method to not be found.
- *
- * @since 1.1.0
- */
- protected Object getMethodValue(Commands.ValueObject value) throws FailedProxyException {
- Object method = connHandler.getInvokableObject(value);
- // It is either a method directly or is an expression proxy.
- if (value.type == Commands.INT) {
- // It is an expression proxy request.
- Object[] expvalue = new Object[2];
- try {
- exp.getExpressionProxy(((Integer) method).intValue(), expvalue);
- method = expvalue[0];
- } catch (NoExpressionValueException e) {
- // See if there is a failed proxy.
- if (e.getProxy() != null) {
- FailedRemoteExpressionProxy failure = (FailedRemoteExpressionProxy) e.getProxy();
- throw new FailedProxyException((Throwable) failure.getValue());
- } else
- throw new FailedProxyException(new NoSuchMethodException()); // This shouldn't of occurred.
- }
- }
- return method;
- }
-
- /**
- * Get the field out of the value object sent in. It can handle the field sent or
- * as an expression proxy to a field expression proxy.
- * @param value
- * @return field if a field or string if a string or get the field if an expression proxy.
- * @throws FailedProxyException Wrappers the real throwable that caused the field to not be found.
- *
- * @since 1.1.0
- */
- protected Object getFieldValue(Commands.ValueObject value) throws FailedProxyException {
- Object field = connHandler.getInvokableObject(value);
- // It is either a field directly or is an expression proxy.
- if (value.type == Commands.INT) {
- // It is an expression proxy request.
- Object[] expvalue = new Object[2];
- try {
- exp.getExpressionProxy(((Integer) field).intValue(), expvalue);
- field = expvalue[0];
- } catch (NoExpressionValueException e) {
- // See if there is a failed proxy.
- if (e.getProxy() != null) {
- FailedRemoteExpressionProxy failure = (FailedRemoteExpressionProxy) e.getProxy();
- throw new FailedProxyException((Throwable) failure.getValue());
- } else
- throw new FailedProxyException(new NoSuchFieldException()); // This shouldn't of occurred.
-
- }
- }
- return field;
- }
-
- /**
- * Pull the Expression Proxy value into the result object.
- * @param proxyID
- * @param result
- * @return <code>true</code> if value could be returned, <code>false</code> if it was no expression value assigned.
- *
- * @since 1.1.0
- */
- public boolean pullExpressionProxyValue(int proxyID, Object[] result) {
- try {
- exp.pullExpressionProxyValue(proxyID, result);
- return true;
- } catch (NoExpressionValueException e) {
- }
- return false;
- }
-
- private static class RemoteExpressionProxy implements InternalExpressionProxy {
-
-
- private final int proxyID;
- private Object value;
- private Class type;
- private boolean set;
-
- public RemoteExpressionProxy(int proxyID) {
- this.proxyID = proxyID;
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.proxy.initParser.tree.InternalExpressionProxy#getProxyID()
- */
- public int getProxyID() {
- return proxyID;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.proxy.initParser.tree.InternalExpressionProxy#getType()
- */
- public Class getType() {
- return type;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.proxy.initParser.tree.InternalExpressionProxy#getValue()
- */
- public Object getValue() {
- return value;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.proxy.initParser.tree.InternalExpressionProxy#isSet()
- */
- public boolean isSet() {
- return set;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jem.internal.proxy.initParser.tree.InternalExpressionProxy#setProxy(java.lang.Object, java.lang.Class)
- */
- public void setProxy(Object value, Class type) {
- this.value = value;
- this.type = type;
- set = true;
- }
-
- public boolean isFailedExpression() {
- return false;
- }
- }
-
- /**
- * Used for the java.lang.reflect things (class, field, method) to indicate
- * why they aren't found.
- * <p>
- * The exception will be placed into value, BUT this should never be sent
- * back to the caller. It is intended only as a place-holder for subsequent
- * usage. Use the {@link RemoteExpressionProxy#isFailedExpression()} method
- * to determine if it is a failed one.
- * <p>
- * This is used because the reflect calls are done out of sequence from where
- * they are used and so if there was an error, the error is reported in the
- * wrong place.
- *
- * @since 1.1.0
- */
- private static class FailedRemoteExpressionProxy extends RemoteExpressionProxy {
-
- public FailedRemoteExpressionProxy(int proxyID) {
- super(proxyID);
- }
-
- public boolean isFailedExpression() {
- return true;
- }
-
- public boolean isSet() {
- return false; // This should never be considered to be set. It is holder of info only.
- }
-
- }
-
-
- /**
- * Pull the value.
- *
- * @return r[0] is the value, r[1] is the type of the value.
- * @throws NoExpressionValueException
- *
- * @since 1.0.0
- */
- public Object[] pullValue() throws NoExpressionValueException {
- Object[] result = new Object[2];
- exp.pullValue(result);
- return result;
- }
-
- /**
- * Close out things.
- *
- * @since 1.0.0
- */
- public void close() {
- exp.close();
- }
-
- /**
- * Get the throwable error.
- * @return
- *
- * @since 1.1.0
- */
- public Throwable getErrorThrowable() {
- return exp.getErrorThrowable();
- }
-
- /**
- * Return whether there were no errors or not.
- * @return
- *
- * @since 1.1.0
- */
- public boolean noErrors() {
- return exp.noErrors();
- }
-
- /**
- * Return whether there is a no expression value exception or not.
- * @return
- *
- * @since 1.1.0
- */
- public boolean isNoExpressionValue() {
- return exp.isNoExpressionValue();
- }
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/IdentityMap.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/IdentityMap.java
deleted file mode 100644
index b0583e738..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/IdentityMap.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: IdentityMap.java,v $
- * $Revision: 1.4 $ $Date: 2005/08/24 20:39:08 $
- */
-
-
-import java.util.*;
-/**
- * A HashMap where the key is
- * done as an identity (i.e. found by '==' not equals()).
- */
-
-public class IdentityMap extends HashMap{
-
- /**
- * Comment for <code>serialVersionUID</code>
- *
- * @since 1.1.0
- */
- private static final long serialVersionUID = -6817274833221383683L;
-
- /**
- * Key that returns true on equals() only
- * if the item it is wrappering is '=='
- * not equals()
- */
- static class IdentityKey {
-
- public static IdentityKey createKey(Object obj) {
- return obj != null ? new IdentityKey(obj) : null;
- }
-
- final Object o;
-
- public IdentityKey(Object obj) {
- o = obj;
- }
-
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (!(obj instanceof IdentityKey)) return false;
- if (this.o == (((IdentityKey) obj).o)) return true;
- return false;
- }
-
- public int hashCode() {
- return o.hashCode();
- }
- }
-
- public IdentityMap() {
- }
-
- public IdentityMap(int capacity) {
- super(capacity);
- }
-
- public IdentityMap(int capacity, float loadFactor) {
- super(capacity, loadFactor);
- }
-
- public boolean containsKey(Object key) {
- return super.containsKey(IdentityKey.createKey(key));
- }
-
- public Object get(Object key) {
- return super.get(IdentityKey.createKey(key));
- }
-
- public Object put(Object key, Object value) {
- return super.put(IdentityKey.createKey(key), value);
- }
-
- public Object remove(Object key) {
- return super.remove(IdentityKey.createKey(key));
- }
-
- /**
- * NOTE: Didn't bother implementing entrySet(). If that becomes
- * needed, then it will be implemented.
- */
- public Set entrySet() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMApplication.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMApplication.java
deleted file mode 100644
index 570d66305..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMApplication.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: RemoteVMApplication.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-
-/**
- * The application to run to kick off the remote VM server side.
- *
- *
- * All this does is start the Server Thread and waits for it to finish.
- * This allows other mains to have a server thread, and some other
- * threads if they wished. They could start the server thread too
- * and some other thread, and then wait for both to finish.
- */
-
-public class RemoteVMApplication {
-
-public static void main(java.lang.String[] args) {
- String serverName = "Server Thread"; //$NON-NLS-1$
- if (System.getProperty("proxyvm.servername") != null) //$NON-NLS-1$
- serverName = serverName + "-" + System.getProperty("proxyvm.servername"); //$NON-NLS-1$ //$NON-NLS-2$
- Thread t = new RemoteVMServerThread(serverName);
- t.start();
- try {
- t.join();
- } catch (Exception e) {
- }
- System.exit(0);
-}
-
-
-
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMServerThread.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMServerThread.java
deleted file mode 100644
index 242093458..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/RemoteVMServerThread.java
+++ /dev/null
@@ -1,717 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: RemoteVMServerThread.java,v $
- * $Revision: 1.13 $ $Date: 2005/12/14 21:23:46 $
- */
-
-
-import java.util.*;
-import java.io.*;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.*;
-import org.eclipse.jem.internal.proxy.common.remote.*;
-import org.eclipse.jem.internal.proxy.common.*;
-/**
- * RemoteVM Server Thread. This thread is the one
- * that waits for connections and spins off
- * server connection threads. It manages the
- * connection threads and handles shutting them
- * down.
- *
- * System Properties:
- * proxyvm.port - Port number to use for the ServerSocket (default is 8888)
- * proxyvm.bufsize - Buffer size to use for TCP/IP buffers (default is system default)
- */
-
-public class RemoteVMServerThread extends Thread implements IVMServer, IVMCallbackServer {
- protected List threads = Collections.synchronizedList(new LinkedList()); // List of active threads.
- protected ServerSocket server; // Server Socket for this application
- private int highestIdentityID = 0; // Identity codes to identify objects between server and client.
- private Map objectToIDMap;
- private HashMap idToObjectMap = new HashMap(100); // Map from identity id to object
-
- protected Stack fCallbackHandlerPool = new Stack(); // Stack of free callback handlers
- protected static int NUMBER_FREE_CALLBACKS = 5; // Number of free callback handlers to keep open.
-
- public static int ID_NOT_FOUND = Commands.NOT_AN_ID; // The id was not found in the table.
-
- protected int masterIDESocketPort = -1; // Port of master server socket on IDE. Used for special global requests.
- protected int registryKey = -1; // Key of registry on the IDE.
-
- // Kludge: Bug in Linux 1.3.xxx of JVM. Closing a socket while the socket is being read/accept will not interrupt the
- // wait. Need to timeout to the socket read/accept before the socket close will be noticed. This has been fixed
- // in Linux 1.4. So on Linux 1.3 need to put timeouts in on those sockets that can be separately closed while reading/accepting.
- static boolean LINUX_1_3 = "linux".equalsIgnoreCase(System.getProperty("os.name")) && System.getProperty("java.version","").startsWith("1.3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-
- // If version 1.3.x, we need to use our IdentidyMap, if 1.4 or greater then we can use Java's IdentidyHashMap, which is more efficient than ours.
- static Constructor IDENTIDYMAP_CLASS_CTOR;
- static {
- Class idClass;
- try {
- idClass = Class.forName("java.util.IdentityHashMap"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- idClass = IdentityMap.class;
- }
- try {
- IDENTIDYMAP_CLASS_CTOR = idClass.getConstructor(new Class[] {Integer.TYPE});
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
- }
-
- public RemoteVMServerThread(String name) {
- super(name);
- try {
- objectToIDMap = (Map) IDENTIDYMAP_CLASS_CTOR.newInstance(new Object[] {new Integer(100)});
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
-
- // The purpose of this thread is to wait 5 minutes, then see if the IDE is still
- // up. If it isn't it will go down. This is safety mechanism
- // in case the client went down without cleaning up and telling the server to go down.
- // That way it won't hang around forever.
- private boolean goingDown = false;
- private Thread safeClean = new Thread(new Runnable() {
- public void run() {
- while (!goingDown) {
- if (Thread.interrupted())
- continue; // Get to clean uninterrupted state.
- try {
- Thread.sleep(5 * 60 * 1000); // Sleep five minutes
- // Test if IDE still up.
- if (!isAlive()) {
- System.err.println("No registry available to connect with after five minutes. Shutting down."); //$NON-NLS-1$
- requestShutdown();
- break;
- }
- } catch (InterruptedException e) {
- }
- }
- }
-
- /*
- * See if still alive
- */
- private boolean isAlive() {
- Socket socket = getSocket();
- if (socket != null) {
- try {
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- DataInputStream in = new DataInputStream(socket.getInputStream());
-
- try {
- out.writeByte(Commands.ALIVE);
- out.writeInt(registryKey);
- out.flush();
- return in.readBoolean();
- // Now get the result.
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- }
- try {
- out.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- socket.close();
- } catch (IOException e) {
- e.printStackTrace(); // They should be closing. If they aren't, then they accumulate and master server will start rejecting new ones.
- }
- }
- }
-
- return false;
- }
-
- }, "Timeout Termination Thread"); //$NON-NLS-1$
-
-
- public void run() {
-
- // Initialize the mapping table with certain pre-defined ids.
- synchronized(objectToIDMap) {
- objectToIDMap.put(Void.TYPE, new Integer(Commands.VOID_TYPE));
- idToObjectMap.put(new Integer(Commands.VOID_TYPE), Void.TYPE);
-
- objectToIDMap.put(Boolean.TYPE, new Integer(Commands.BOOLEAN_TYPE));
- idToObjectMap.put(new Integer(Commands.BOOLEAN_TYPE), Boolean.TYPE);
- objectToIDMap.put(Boolean.class, new Integer(Commands.BOOLEAN_CLASS));
- idToObjectMap.put(new Integer(Commands.BOOLEAN_CLASS), Boolean.class);
-
- objectToIDMap.put(Integer.TYPE, new Integer(Commands.INTEGER_TYPE));
- idToObjectMap.put(new Integer(Commands.INTEGER_TYPE), Integer.TYPE);
- objectToIDMap.put(Integer.class, new Integer(Commands.INTEGER_CLASS));
- idToObjectMap.put(new Integer(Commands.INTEGER_CLASS), Integer.class);
-
- objectToIDMap.put(Byte.TYPE, new Integer(Commands.BYTE_TYPE));
- idToObjectMap.put(new Integer(Commands.BYTE_TYPE), Byte.TYPE);
- objectToIDMap.put(Byte.class, new Integer(Commands.BYTE_CLASS));
- idToObjectMap.put(new Integer(Commands.BYTE_CLASS), Byte.class);
-
- objectToIDMap.put(Short.TYPE, new Integer(Commands.SHORT_TYPE));
- idToObjectMap.put(new Integer(Commands.SHORT_TYPE), Short.TYPE);
- objectToIDMap.put(Short.class, new Integer(Commands.SHORT_CLASS));
- idToObjectMap.put(new Integer(Commands.SHORT_CLASS), Short.class);
-
- objectToIDMap.put(Long.TYPE, new Integer(Commands.LONG_TYPE));
- idToObjectMap.put(new Integer(Commands.LONG_TYPE), Long.TYPE);
- objectToIDMap.put(Long.class, new Integer(Commands.LONG_CLASS));
- idToObjectMap.put(new Integer(Commands.LONG_CLASS), Long.class);
-
- objectToIDMap.put(Character.TYPE, new Integer(Commands.CHARACTER_TYPE));
- idToObjectMap.put(new Integer(Commands.CHARACTER_TYPE), Character.TYPE);
- objectToIDMap.put(Character.class, new Integer(Commands.CHARACTER_CLASS));
- idToObjectMap.put(new Integer(Commands.CHARACTER_CLASS), Character.class);
-
- objectToIDMap.put(Double.TYPE, new Integer(Commands.DOUBLE_TYPE));
- idToObjectMap.put(new Integer(Commands.DOUBLE_TYPE), Double.TYPE);
- objectToIDMap.put(Double.class, new Integer(Commands.DOUBLE_CLASS));
- idToObjectMap.put(new Integer(Commands.DOUBLE_CLASS), Double.class);
-
- objectToIDMap.put(Float.TYPE, new Integer(Commands.FLOAT_TYPE));
- idToObjectMap.put(new Integer(Commands.FLOAT_TYPE), Float.TYPE);
- objectToIDMap.put(Float.class, new Integer(Commands.FLOAT_CLASS));
- idToObjectMap.put(new Integer(Commands.FLOAT_CLASS), Float.class);
-
- objectToIDMap.put(String.class, new Integer(Commands.STRING_CLASS));
- idToObjectMap.put(new Integer(Commands.STRING_CLASS), String.class);
-
- objectToIDMap.put(java.math.BigDecimal.class, new Integer(Commands.BIG_DECIMAL_CLASS));
- idToObjectMap.put(new Integer(Commands.BIG_DECIMAL_CLASS), java.math.BigDecimal.class);
-
- objectToIDMap.put(java.math.BigInteger.class, new Integer(Commands.BIG_INTEGER_CLASS));
- idToObjectMap.put(new Integer(Commands.BIG_INTEGER_CLASS), java.math.BigInteger.class);
-
- objectToIDMap.put(Number.class, new Integer(Commands.NUMBER_CLASS));
- idToObjectMap.put(new Integer(Commands.NUMBER_CLASS), Number.class);
-
- objectToIDMap.put(Throwable.class, new Integer(Commands.THROWABLE_CLASS));
- idToObjectMap.put(new Integer(Commands.THROWABLE_CLASS), Throwable.class);
-
-
- objectToIDMap.put(Object.class, new Integer(Commands.OBJECT_CLASS));
- idToObjectMap.put(new Integer(Commands.OBJECT_CLASS), Object.class);
-
- objectToIDMap.put(Class.class, new Integer(Commands.CLASS_CLASS));
- idToObjectMap.put(new Integer(Commands.CLASS_CLASS), Class.class);
-
- objectToIDMap.put(java.lang.reflect.AccessibleObject.class, new Integer(Commands.ACCESSIBLEOBJECT_CLASS));
- idToObjectMap.put(new Integer(Commands.ACCESSIBLEOBJECT_CLASS), java.lang.reflect.AccessibleObject.class);
-
- objectToIDMap.put(java.lang.reflect.Method.class, new Integer(Commands.METHOD_CLASS));
- idToObjectMap.put(new Integer(Commands.METHOD_CLASS), java.lang.reflect.Method.class);
-
- objectToIDMap.put(java.lang.reflect.Constructor.class, new Integer(Commands.CONSTRUCTOR_CLASS));
- idToObjectMap.put(new Integer(Commands.CONSTRUCTOR_CLASS), java.lang.reflect.Constructor.class);
-
- objectToIDMap.put(java.lang.reflect.Field.class, new Integer(Commands.FIELD_CLASS));
- idToObjectMap.put(new Integer(Commands.FIELD_CLASS), java.lang.reflect.Field.class);
-
- objectToIDMap.put(IVMServer.class, new Integer(Commands.IVMSERVER_CLASS));
- idToObjectMap.put(new Integer(Commands.IVMSERVER_CLASS), IVMServer.class);
-
- objectToIDMap.put(ICallback.class, new Integer(Commands.ICALLBACK_CLASS));
- idToObjectMap.put(new Integer(Commands.ICALLBACK_CLASS), ICallback.class);
-
- objectToIDMap.put(this, new Integer(Commands.REMOTESERVER_ID));
- idToObjectMap.put(new Integer(Commands.REMOTESERVER_ID), this);
-
- objectToIDMap.put(RemoteVMServerThread.class, new Integer(Commands.REMOTEVMSERVER_CLASS));
- idToObjectMap.put(new Integer(Commands.REMOTEVMSERVER_CLASS), RemoteVMServerThread.class);
-
- objectToIDMap.put(Thread.class, new Integer(Commands.THREAD_CLASS));
- idToObjectMap.put(new Integer(Commands.THREAD_CLASS), Thread.class);
-
- objectToIDMap.put(ExpressionProcesserController.class, new Integer(Commands.EXPRESSIONPROCESSERCONTROLLER_CLASS));
- idToObjectMap.put(new Integer(Commands.EXPRESSIONPROCESSERCONTROLLER_CLASS), ExpressionProcesserController.class);
-
- try {
- java.lang.reflect.Method getMethod = Class.class.getMethod("getMethod", new Class[] {String.class, (new Class[0]).getClass()}); //$NON-NLS-1$
- objectToIDMap.put(getMethod, new Integer(Commands.GET_METHOD_ID));
- idToObjectMap.put(new Integer(Commands.GET_METHOD_ID), getMethod);
-
- java.lang.reflect.Method initMethod = ICallback.class.getMethod("initializeCallback", new Class[] {IVMCallbackServer.class, Integer.TYPE}); //$NON-NLS-1$
- objectToIDMap.put(initMethod, new Integer(Commands.INITIALIZECALLBACK_METHOD_ID));
- idToObjectMap.put(new Integer(Commands.INITIALIZECALLBACK_METHOD_ID), initMethod);
-
- } catch (NoSuchMethodException e) {
- // Shouldn't really ever occur.
- }
-
- highestIdentityID = Commands.FIRST_FREE_ID;
- }
-
- masterIDESocketPort = Integer.getInteger("proxyvm.masterPort", -1).intValue(); //$NON-NLS-1$
- if (masterIDESocketPort == -1) {
- // No ports specified, need to just shutdown.
- shutdown();
- return;
- }
-
- registryKey = Integer.getInteger("proxyvm.registryKey", -1).intValue(); //$NON-NLS-1$
- if (registryKey == -1) {
- // No registry specified, need to just shutdown.
- shutdown();
- return;
- }
-
- safeClean.setPriority(Thread.MIN_PRIORITY);
- safeClean.start();
- boolean trying = true;
- try {
- server = new ServerSocket(0, 50 , InetAddress.getByName("localhost")); //$NON-NLS-1$
- trying = false;
- if (LINUX_1_3)
- server.setSoTimeout(1000); // Linux 1.3 bug, see comment on LINUX_1_3
- if (registerServer(server.getLocalPort())) {
- while(server != null) {
- Socket incoming = null;
- try {
- incoming = server.accept();
- } catch (InterruptedIOException e) {
- continue; // Timeout, try again
- } catch (NullPointerException e) {
- continue; // Server could of gone null after test in while, means shutting down. This probably would only happen Linux 1.3.
- }
- Thread st = new ConnectionThread(incoming, this, "Connection Thread"); //$NON-NLS-1$
- threads.add(st);
- safeClean.interrupt(); // Let safeClean know there is a change
- st.start();
- // Null out locals so they can be GC'd since this is a long running loop.
- st = null;
- incoming = null;
- }
- }
- } catch (SocketException e) {
- if (trying || server != null)
- e.printStackTrace(); // Exception and not shutdown request, so print stack trace.
- } catch (Throwable e) {
- e.printStackTrace();
- }
-
- // We've had an exception, either something really bad, or we were closed,
- // so go through shutdowns.
- shutdown();
- }
-
-
- /**
- * Get an identityID, return -1 if not found.
- */
- public int getIdentityID(Object anObject) {
- synchronized(objectToIDMap) {
- Integer id = (Integer) objectToIDMap.get(anObject);
- return id != null ? id.intValue() : ID_NOT_FOUND;
- }
- }
-
- /**
- * Get an identityID and add it if not found. Place the id in the
- * ValueObject passed in and return whether it was added (true) or was already in table (false)
- */
- public boolean getIdentityID(Object anObject, Commands.ValueObject intoValue ) {
- boolean added = false;
- synchronized(objectToIDMap) {
- Integer id = (Integer) objectToIDMap.get(anObject);
- if (id == null) {
- do {
- if (++highestIdentityID == Commands.NOT_AN_ID)
- ++highestIdentityID; // Don't let -1 be a valid id.
- id = new Integer(highestIdentityID);
- } while (idToObjectMap.containsKey(id)); // Make sure not in use, really shouldn't ever happen because we have over 4 billion before it wraps back
- objectToIDMap.put(anObject, id);
- idToObjectMap.put(id, anObject);
- added = true;
- }
- intoValue.setObjectID(id.intValue());
- }
- return added;
- }
-
- /**
- * Remove an identity object from the mapping.
- */
- public void removeObject(Object anObject) {
- synchronized(objectToIDMap) {
- Integer id = (Integer) objectToIDMap.remove(anObject);
- idToObjectMap.remove(id);
- }
- }
-
- /**
- * Remove an identity object from the mapping, given the id.
- */
- public void removeObject(int id) {
- synchronized(objectToIDMap) {
- Object o = idToObjectMap.remove(new Integer(id));
- objectToIDMap.remove(o);
- }
- }
-
- /**
- * Get the object for an identity id
- */
- public Object getObject(int id) {
- synchronized(objectToIDMap) {
- return idToObjectMap.get(new Integer(id));
- }
- }
-
- /**
- * Remove a thread from the list.
- */
- public void removeConnectionThread(Thread thread) {
- threads.remove(thread);
- safeClean.interrupt(); // Let safe clean know there is a change.
- }
-
- /**
- * Use this to request a shutdown. If the server hasn't even been
- * created yet, this will return false.
- */
- public boolean requestShutdown() {
- if (server == null)
- return false;
- // Closing the server socket should cause a break.
- try {
- ServerSocket srv = server;
- server = null; // So that server knows it is being shutdown and not print exception msg.
- srv.close();
- } catch (Exception e) {
- }
- return true;
- }
-
- /**
- * Request a callback stream to write to.
- * When done, the stream should be closed to release the connection.
- */
- public OutputStream requestStream(int callbackID, int msgID) throws CommandException {
- CallbackHandler h = (CallbackHandler) getFreeCallbackHandler();
- if (h == null)
- throw new CommandException("No callback handler retrieved.", null); //$NON-NLS-1$
- h.initiateCallbackStream(callbackID, msgID);
- return new CallbackOutputStream(h, this);
- }
-
- protected void shutdown() {
- goingDown = true;
- safeClean.interrupt(); // Let safeClean know to come down.
-
- if (server != null)
- try {
- server.close(); // Close it so that no more requests can be made.
- } catch (Exception e) {
- }
-
- // Go through each thread and ask it to close. Make a copy of the list so that we
- // won't get into deadlocks.
- ConnectionThread[] threadsArray = (ConnectionThread[]) threads.toArray(new ConnectionThread[0]);
- for (int i=0; i<threadsArray.length; i++) {
- // This is a harsh way to shut a connection down, but there's no
- // other way I know of to interrupt the read on a socket.
- threadsArray[i].close();
- }
-
- // Now that they've been told to close, wait on each one to finish.
- for (int i=0; i<threadsArray.length; i++)
- try {
- threadsArray[i].join(10000); // Wait ten seconds, if longer, just go on to next one.
- if (threadsArray[i].isAlive())
- System.out.println("*** Connection "+i+" did not die."); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (InterruptedException e) {
- }
-
- if (safeClean.isAlive()) {
- try {
- safeClean.join(10000);
- if (safeClean.isAlive())
- System.out.println("*** Cleanup thread did not die."); //$NON-NLS-1$
- } catch (InterruptedException e) {
- }
- }
-
- // Now close the callbacks.
- synchronized(fCallbackHandlerPool) {
- // Now we walk through all of the free handlers and close them properly.
- Iterator itr = fCallbackHandlerPool.iterator();
- while (itr.hasNext()) {
- ((CallbackHandler) itr.next()).closeHandler();
- }
-
- fCallbackHandlerPool.clear();
- }
-
- List runnables = null;
- synchronized (this) {
- runnables = shutdownRunnables;
- shutdownRunnables = null;
- }
- if (runnables != null) {
- for (Iterator itr = runnables.iterator(); itr.hasNext();) {
- try {
- ((Runnable) itr.next()).run();
- } catch (RuntimeException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- /**
- * Return a free callback handler
- */
- public ICallbackHandler getFreeCallbackHandler() {
- synchronized(fCallbackHandlerPool) {
- if (!fCallbackHandlerPool.isEmpty())
- return (ICallbackHandler) fCallbackHandlerPool.pop();
- // else we need to allocate one.
- return createCallbackHandler();
- }
- }
-
- /**
- * Make a new callback handler
- */
- protected ICallbackHandler createCallbackHandler() {
- Socket callbackSocket = requestCallbackSocket();
- if (callbackSocket != null) {
- CallbackHandler handler = new CallbackHandler(callbackSocket, this);
- if (handler.isConnected())
- return handler;
-
- // Failed, close the socket.
- try {
- callbackSocket.close();
- } catch (IOException e) {
- }
- }
- return null;
- }
-
- /**
- * Free the handler
- */
- public void returnCallbackHandler(ICallbackHandler aHandler) {
- CallbackHandler handler = (CallbackHandler) aHandler;
- if (handler.isConnected())
- synchronized (fCallbackHandlerPool) {
- if (fCallbackHandlerPool.size() < NUMBER_FREE_CALLBACKS)
- fCallbackHandlerPool.push(handler);
- else
- handler.closeHandler(); // We don't need to maintain more than five free connections.
- }
- }
-
- /**
- * Process a callback.
- */
- public Object doCallback(ICallbackRunnable run) throws CommandException {
- CallbackHandler handler = (CallbackHandler) getFreeCallbackHandler();
- if (handler != null) {
- try {
- try {
- return run.run(handler);
- } catch (CommandErrorException e) {
- // This is command error, connection still good, don't retry, just pass it on.
- // It means the other side said I processed it, but there is an error.
- throw e;
- } catch (CommandException e) {
- if (!e.isRecoverable()) {
- // Close this handler and try a new one, one more time.
- handler.closeHandler();
- handler = (CallbackHandler) getFreeCallbackHandler();
- try {
- return run.run(handler);
- } catch (CommandException eAgain) {
- // It failed again, just close the connection and rethrow the exception.
- handler.closeHandler();
- throw eAgain;
- }
- } else
- throw e; // Recoverable, rethrow exception.
- }
- } finally {
- returnCallbackHandler(handler);
- }
- } else
- throw new CommandException("No callback handler retrieved.", null); //$NON-NLS-1$
-
- }
-
- /*
- * Register the server. Return if ide still active
- */
- private boolean registerServer(int vmserverPort) {
- Socket socket = getSocket();
- if (socket != null) {
- try {
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- DataInputStream in = new DataInputStream(socket.getInputStream());
-
- try {
- out.writeByte(Commands.REMOTE_STARTED);
- out.writeInt(registryKey);
- out.writeInt(vmserverPort);
- out.flush();
- return in.readBoolean();
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- }
- try {
- out.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- socket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- }
-
- return false;
- }
-
- /*
- * Request the callback socket. <code>null</code> if there isn't one.
- */
- private Socket requestCallbackSocket() {
- Socket socket = getSocket();
- if (socket != null) {
- boolean closeSocket = true;
- try {
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- DataInputStream in = new DataInputStream(socket.getInputStream());
-
- try {
- out.writeByte(Commands.ATTACH_CALLBACK);
- out.writeInt(registryKey);
- out.flush();
- closeSocket = !in.readBoolean();
- return !closeSocket ? socket : null;
- } finally {
- if (closeSocket) {
- try {
- in.close();
- } catch (IOException e) {
- }
- try {
- out.close();
- } catch (IOException e) {
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (closeSocket) {
- try {
- socket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- return null;
- }
-
-
-
- protected Socket getSocket() {
- // We are putting it off into a thread because there are no timeout capabilities on getting a socket.
- // So we need to allow for that.
- final Socket[] scArray = new Socket[1];
- final boolean[] waiting = new boolean[] {true};
- Thread doIt = new Thread(new Runnable() {
- public void run() {
- try {
- Socket sc = new Socket("localhost", masterIDESocketPort); //$NON-NLS-1$
- synchronized (this) {
- if (waiting[0])
- scArray[0] = sc;
- else
- sc.close(); // We are no longer waiting on this thread so close the socket since no one will use it.
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
-
- doIt.start();
- while (true) {
- try {
- doIt.join(60000);
- synchronized (doIt) {
- waiting[0] = false; // To let it know we are no longer waiting
- }
- break;
- } catch (InterruptedException e) {
- }
- }
-
- if (scArray[0] == null) {
- System.out.println("Couldn't retrieve a socket from master server in 60 seconds."); //$NON-NLS-1$
- return null; // Couldn't get one, probably server is down.
- }
-
- return scArray[0];
- }
-
- private List shutdownRunnables;
-
- public synchronized void addShutdownListener(Runnable runnable) {
- if (shutdownRunnables == null) {
- shutdownRunnables = new ArrayList();
- } else if (shutdownRunnables.contains(runnable))
- return;
- shutdownRunnables.add(runnable);
- }
-
- public synchronized void removeShutdownListener(Runnable runnable) {
- if (shutdownRunnables != null)
- shutdownRunnables.remove(runnable);
- }
-
-
- public IVMServer getIVMServer() {
- return this;
- }
-}
diff --git a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/StackTraceUtility.java b/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/StackTraceUtility.java
deleted file mode 100644
index bdeb6aecf..000000000
--- a/plugins/org.eclipse.jem.proxy/vm_remotevm/org/eclipse/jem/internal/proxy/vm/remote/StackTraceUtility.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jem.internal.proxy.vm.remote;
-/*
- * $RCSfile: StackTraceUtility.java,v $
- * $Revision: 1.3 $ $Date: 2005/08/24 20:39:08 $
- */
-
-
-import java.io.*;
-/**
- * A utility to get the stack trace from an exception
- * back to the client.
- */
-public class StackTraceUtility {
-
- public static String printStackTrace(Throwable t) {
- StringWriter writer = new StringWriter();
- t.printStackTrace(new PrintWriter(writer));
- return writer.toString();
- }
-
-
-}

Back to the top