From a4fe1498f28488a8dbd8d4c5efcd9f26266f5f34 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Thu, 31 Jan 2013 11:15:05 +0000 Subject: [PATCH] Huge change that refs #24 and #25 All RMI has been removed. GUI not working properly right now, but at least the code compiles. --- src/eva2/tools/jproxy/ComAdapter.java | 612 ------------------ src/eva2/tools/jproxy/JProxyRemoteThread.java | 107 --- src/eva2/tools/jproxy/MainAdapter.java | 33 - src/eva2/tools/jproxy/MainAdapterClient.java | 19 - .../tools/jproxy/MainAdapterClientImpl.java | 77 --- src/eva2/tools/jproxy/MainAdapterImpl.java | 155 ----- src/eva2/tools/jproxy/RMIConnection.java | 99 --- .../tools/jproxy/RMIInvocationHandler.java | 27 - .../jproxy/RMIInvocationHandlerImpl.java | 147 ----- src/eva2/tools/jproxy/RMIProxyLocal.java | 123 ---- .../tools/jproxy/RMIProxyLocalThread.java | 121 ---- src/eva2/tools/jproxy/RMIProxyRemote.java | 125 ---- .../tools/jproxy/RMIProxyRemoteThread.java | 142 ---- src/eva2/tools/jproxy/RMIServer.java | 162 ----- .../RMIServerNotAvailableException.java | 22 - .../jproxy/RMIThreadInvocationHandler.java | 21 - .../RMIThreadInvocationHandlerImpl.java | 161 ----- .../tools/jproxy/RemoteStateListener.java | 20 - src/eva2/tools/jproxy/ThreadProxy.java | 98 --- src/eva2/tools/jproxy/ThreadWrapper.java | 76 --- src/eva2/tools/jproxy/XThread.java | 204 ------ 21 files changed, 2551 deletions(-) delete mode 100644 src/eva2/tools/jproxy/ComAdapter.java delete mode 100644 src/eva2/tools/jproxy/JProxyRemoteThread.java delete mode 100644 src/eva2/tools/jproxy/MainAdapter.java delete mode 100644 src/eva2/tools/jproxy/MainAdapterClient.java delete mode 100644 src/eva2/tools/jproxy/MainAdapterClientImpl.java delete mode 100644 src/eva2/tools/jproxy/MainAdapterImpl.java delete mode 100644 src/eva2/tools/jproxy/RMIConnection.java delete mode 100644 src/eva2/tools/jproxy/RMIInvocationHandler.java delete mode 100644 src/eva2/tools/jproxy/RMIInvocationHandlerImpl.java delete mode 100644 src/eva2/tools/jproxy/RMIProxyLocal.java delete mode 100644 src/eva2/tools/jproxy/RMIProxyLocalThread.java delete mode 100644 src/eva2/tools/jproxy/RMIProxyRemote.java delete mode 100644 src/eva2/tools/jproxy/RMIProxyRemoteThread.java delete mode 100644 src/eva2/tools/jproxy/RMIServer.java delete mode 100644 src/eva2/tools/jproxy/RMIServerNotAvailableException.java delete mode 100644 src/eva2/tools/jproxy/RMIThreadInvocationHandler.java delete mode 100644 src/eva2/tools/jproxy/RMIThreadInvocationHandlerImpl.java delete mode 100644 src/eva2/tools/jproxy/RemoteStateListener.java delete mode 100644 src/eva2/tools/jproxy/ThreadProxy.java delete mode 100644 src/eva2/tools/jproxy/ThreadWrapper.java delete mode 100644 src/eva2/tools/jproxy/XThread.java diff --git a/src/eva2/tools/jproxy/ComAdapter.java b/src/eva2/tools/jproxy/ComAdapter.java deleted file mode 100644 index eab904b9..00000000 --- a/src/eva2/tools/jproxy/ComAdapter.java +++ /dev/null @@ -1,612 +0,0 @@ -package eva2.tools.jproxy; - -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.3 $ - * $Date: 2004/04/28 07:50:32 $ - * $Author: ulmerh $ - */ -import java.net.MalformedURLException; -import java.rmi.Naming; -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.rmi.registry.Registry; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * - */ -public class ComAdapter { - private static final Logger LOGGER = Logger.getLogger(ComAdapter.class.getName()); - public static final int PORT = 1099; - public static final String SEP = "_"; - static protected ComAdapter m_instance = null; - - public Registry m_Registry = null; - private ArrayList m_Connections = new ArrayList(); - private String hostName; - private ArrayList m_HostNameList = new ArrayList(); - private ArrayList m_AvailableHostNameList = new ArrayList(); -// private String m_RemoteAdapterName; - private String userName; - private int m_ownHostIndex = 0; - protected RMIServer m_RMIServer; - private String serverListSeparator = ","; - private boolean gettingRegistry; - - /** - * - */ - public static ComAdapter getInstance() { - if (m_instance != null) { - return m_instance; - } - m_instance = new ComAdapter(); - return m_instance; - } - - /** - * - */ - protected ComAdapter() { - try { - userName = System.getProperty("user.name"); - } catch(SecurityException ex) { - /* This exception is expected to happen when - * we are using Java WebStart. - */ - LOGGER.log(Level.INFO, "Username set to: WebStart", ex); - userName = "Webstart"; - } - hostName = "localhost"; //"192.168.0.1"; - - try { - System.setProperty("java.security.policy", "server.policy"); - } catch(AccessControlException ex) { - // ToDo: This happens using webstart - what to do now? - } - launchRMIRegistry(false); - if (!m_HostNameList.contains("localhost")) { - // make sure localhost is in the list - m_HostNameList.add("localhost"); - } - } - - /** - * Parse a string of server names. The comma "," must be used as separator. - * - * @param serverList - */ - public void addServersFromString(String serverList) { - if (serverList != null) { - // parse the servernames - StringTokenizer st = new StringTokenizer(serverList, serverListSeparator); - - while (st.hasMoreTokens()) { - String current = st.nextToken().trim(); - if (!m_HostNameList.contains(current)) { - m_HostNameList.add(current); - } else { - LOGGER.log(Level.FINER, "Server " + current + " was already in list"); - } - } - } - } - - /** - * Add a server list from a Properties instance. The key used is "ServerList". - * - * @param props - */ - public void addServersFromProperties(Properties props) { - String servs = props.getProperty("ServerList"); - addServersFromString(servs); - } - - /** - * Set the separator for the server list string. - * - * @param sep List separator - */ - public void setServerListSeparator(String sep) { - serverListSeparator = sep; - } - - /** - * The separator for the server list string. - * - * @return The list separator - */ - public String getServerListSeparator() { - return serverListSeparator; - } - - /** - * - * @param server An array of servers - */ - public void setServerList(String[] server){ - m_HostNameList.clear(); - for (int i=0;i= m_AvailableHostNameList.size()) { - m_ownHostIndex = 0; - } - hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); - ret = getRMIThreadHandler(c, hostName); - return ret; - } - - /** - * - * - */ - public RMIInvocationHandler getRMIHandler(Object c) { - RMIInvocationHandler ret = null; - while (m_AvailableHostNameList.size() == 0) { - evalAvailableHostNameList(); - if (m_AvailableHostNameList.size() == 0) { - LOGGER.log(Level.WARNING, "No host availabe waiting.."); - } - m_ownHostIndex = 0; - } - m_ownHostIndex++; - if (m_ownHostIndex >= m_AvailableHostNameList.size()) { - m_ownHostIndex = 0; - } - hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); - ret = getRMIHandler(c, hostName); - return ret; - } - -// /** -// * -// */ -// public String getLoad() { -// if (TRACE) -// System.out.println("ComAdapter.getLoad()"); -// String Load = null; -// Load = getConnection(m_ownHostName).getExecOutput("rup " + m_ownHostName); -// if (TRACE) -// System.out.println("Load of Modules on Server !! :" + Load); -//// if (m_LogPanel != null) -//// m_LogPanel.logMessage("Load of Modules on Server !! :" + Load); -// return Load; -// } - -// /** -// * -// */ -// public String gettokens() { -// if (TRACE) -// System.out.println("ComAdapter.gettokens()"); -// String Tokens = null; -// Tokens = getConnection(m_ActualHostName).getExecOutput("tokens"); -// if (TRACE) -// System.out.println("tokens on Server !! :" + Tokens); -// Tokens = getConnection(m_ActualHostName).getExecOutput( -// "klog -principal ulmerh -password "); -// if (TRACE) -// System.out.println("KLOG !!! !! :" + Tokens); -// Tokens = getConnection(m_ActualHostName).getExecOutput("tokens"); -// if (TRACE) -// System.out.println("tokens on Server !! :" + Tokens); -// return Tokens; -// } - - /** - * - */ - public void evalAvailableHostNameList() { - long time = System.currentTimeMillis(); - m_AvailableHostNameList.clear(); - for (int i = 0; i < m_HostNameList.size(); i++) { - if (rmiPing((String) m_HostNameList.get(i)) == true) { - m_AvailableHostNameList.add((String) m_HostNameList.get(i)); - } - String testurl = (String) m_HostNameList.get(i); - for (int j = 1; j < 3; j++) { - if (rmiPing(testurl + "_" + j) == true) { - LOGGER.log(Level.INFO, "Found EvAServer on: " + testurl); - m_AvailableHostNameList.add(testurl + "_" + j); - } - } - } - time = System.currentTimeMillis() - time; - - } - - /** - * - */ - public String[] getAvailableHostNameList() { - if (m_AvailableHostNameList.size() == 0) { - evalAvailableHostNameList(); - } - String[] ret = new String[m_AvailableHostNameList.size()]; - m_AvailableHostNameList.toArray(ret); - return ret; - } - - /** - * - */ - public String[] getHostNameList() { - String[] x = new String[m_HostNameList.size()]; - m_HostNameList.toArray(x); - return x; - } - - /** - * Returns the current hostName set for the adapter. - * - * @return The current hostName. - */ - public String getHostName() { - return hostName; - } - - /** - * Sets hostName and writes it to a file. - * - * @param newHost The new hostName. - */ - public void setHostName(final String newHost) { - hostName = newHost; - try { - java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userRoot(); - prefs.put("hostname", hostName); - } catch (SecurityException ex) { - LOGGER.log(Level.WARNING, "Can't write user preference.", ex); - } - } - - - /** - * Creates a RMI-MainAdapter to host. - * @return - */ - protected MainAdapter createRMIMainConnect(String HostToConnect) { - int len = HostToConnect.indexOf(SEP); - String Host = HostToConnect; - String Number = SEP + "0"; - if (len != -1) { - StringTokenizer st = new StringTokenizer(HostToConnect, SEP); - Host = st.nextToken().trim(); - Number = SEP + st.nextToken().trim(); - } - String MainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME + Number; // attention - - LOGGER.info("RMIConnect to " + HostToConnect); - MainAdapter MainRemoteObject = null; - try { - RMIInvocationHandler invocHandler = (RMIInvocationHandler) Naming.lookup( - "rmi://" + Host + ":" + MainAdapterImpl.PORT + "/" - + MainAdapterName); - MainRemoteObject = getMainAdapter(invocHandler); - - MainRemoteObject.setBuf("Ok."); - LOGGER.info("RMIConnect " + MainRemoteObject.getBuf()); - } catch (MalformedURLException ex) { - LOGGER.log(Level.WARNING, "MalformedURLException: Error while looking up " + ex.getMessage(), ex); - } catch (NotBoundException ex) { - LOGGER.log(Level.WARNING, "NotBoundException: Error while looking up " + ex.getMessage(), ex); - } catch (RemoteException ex) { - LOGGER.log(Level.WARNING, "Error while connecting Host: " + HostToConnect, ex); - return null; - } - return MainRemoteObject; - } - - protected MainAdapter getMainAdapter(RMIInvocationHandler invocHandler) throws RemoteException { - return (MainAdapter) invocHandler.getWrapper(); - } - - /** - * - */ - protected int getNumberOfServersonHost(String testurl) { -// String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME; - String[] list = null; - try { - list = Naming.list("rmi://" + testurl + ":" + MainAdapterImpl.PORT); - } catch (Exception e) { - System.err.println ("Exception : "+testurl ); - return 0; - } - int ret = 0; - for (int i = 0; i < list.length; i++) { - if (list[i].indexOf(MainAdapterImpl.MAIN_ADAPTER_NAME) != -1) { - ret++; - } - } - System.err.println("error in ComAdapter.getNumberOfServersonHost"); - //System.out.println(" ret === "+ret); - return ret; - } - - /** - * - */ - private boolean rmiPing(String testurl) { - MainAdapter Test = null; - int len = testurl.indexOf(SEP); - String Host = testurl; - String Number = "_0"; - if (len != -1) { - StringTokenizer st = new StringTokenizer(testurl, SEP); - Host = st.nextToken().trim(); - Number = SEP + st.nextToken().trim(); - } - String mainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME + - Number; - try { - RMIInvocationHandler x = (RMIInvocationHandler) Naming.lookup("rmi://" + - Host + ":" + MainAdapterImpl.PORT + "/" + mainAdapterName); // attention !! - Test = (MainAdapter) x.getWrapper(); - } catch (Exception ex) { - LOGGER.log(Level.INFO, "No connection to : " + testurl, ex); - return false; - } - return true; - } - - /** - * - */ - public void killServer(String ServerToKill) { - RMIConnection myConnection = getConnection(ServerToKill); - myConnection.killServer(); - this.m_Connections.remove(myConnection); - } - - /** - * - */ - public void killAllServers() { - for (int i = 0; i < m_AvailableHostNameList.size(); i++) { - RMIConnection myConnection = getConnection((String) - m_AvailableHostNameList.get(i)); - myConnection.killServer(); - this.m_Connections.remove(myConnection); - } - } - - /** - * - */ - public void restartServerAllServer() { - for (int i = 0; i < m_AvailableHostNameList.size(); i++) { - RMIConnection myConnection = getConnection((String) - m_AvailableHostNameList.get(i)); - myConnection.restartServer(); - m_Connections.remove(myConnection); - } - } - - /** - * - */ - public void restartServer(String host) { - hostName = host; - restartServer(); - } - - /** - * - */ - public void restartServer() { - if (hostName.equals("localhost")) { // TODO whats this? - return; - } - RMIConnection x = getConnection(hostName); - x.restartServer(); - m_Connections.remove(x); - try { - Thread.sleep(3000); - } catch (Exception e) { - System.err.println("Error in sleep of ExitThread"); - } - } - - public void setRMIRegistry(Registry reg) { - m_Registry = reg; - gettingRegistry = false; - } - - /** - * Install RMIregistry on default port !! - */ - protected void launchRMIRegistry(boolean ownThread) { - if (ownThread) { - Thread t = new Thread(new RMIRegistration(this)); - gettingRegistry = true; - t.start(); - } else { - RMIRegistration rmiReg = new RMIRegistration(this); - gettingRegistry = true; - rmiReg.run(); - } - } - /** - * - */ - public void setLocalRMIServer(RMIServer Server) { - m_RMIServer = Server; - } - - /** - * Just the main for testing the class. - */ - public static void main(String[] args) { - ComAdapter TestApp = ComAdapter.getInstance(); - TestApp.evalAvailableHostNameList(); - TestApp.killAllServers(); - //TestApp.restartServerAllServer(); - } - - /** - * - */ - protected RMIConnection getConnection(String Host) { - for (int i = 0; i < this.m_Connections.size(); i++) { - // search for an already established connection to the given host - // and return it if found - RMIConnection ret = (RMIConnection) m_Connections.get(i); - if (Host.equals(ret.getHostName())) { - return ret; - } - } - // else create and add new RMIConnection - RMIConnection ret = null; - if (Host.equals("localhost") && m_RMIServer != null) { - // this uses rmi on the localhost - ret = createRMIConnection(Host, m_RMIServer.getMainRemoteObject(), - new MainAdapterClientImpl("localhost")); - } else { - MainAdapter Adapter = (MainAdapter)createRMIMainConnect(Host); - if (Adapter != null) { - ret = createRMIConnection(Host, Adapter, - (MainAdapterClient) RMIProxyLocal.newInstance(new MainAdapterClientImpl(Host))); - } - } - if (ret != null) { - m_Connections.add(ret); - } - else { - System.err.println("Warning no valid connection !!"); - } - return ret; - } - - protected RMIConnection createRMIConnection(String Host, MainAdapter mainRemoteObject, MainAdapterClient client) { - return new RMIConnection(Host, mainRemoteObject, client); - } - -// private RMIConnection getConnection(String Host) { -// if (TRACE == true) System.out.println("ComAdapter.getConnection for host :" + Host); -// RMIConnection ret = null; -// for (int i = 0; i < this.m_Connections.size(); i++) { -// ret = (RMIConnection) m_Connections.get(i); -// if (Host.equals(ret.getHostName()) == true) -// return ret; -// } -// // create and add new RMIConnection -// if (Host.equals("localhost") && (m_RMIServer != null)) { -// ret = new RMIConnection(Host, m_RMIServer.getMainRemoteObject(), -// new MainAdapterClientImpl()); -// } else { -// MainAdapter Adapter = createRMIMainConnect(Host); -// if (Adapter != null) -// ret = new RMIConnection(Host, Adapter, -// (MainAdapterClient) -// RMIProxyLocal.newInstance(new MainAdapterClientImpl())); -// } -// if (ret != null) m_Connections.add(ret); -// else System.err.println("Warning no valid connection !!"); -// return ret; -// } -} - -class RMIRegistration implements Runnable { - ComAdapter comAd = null; - private boolean TRACE = false; - Registry reg = null; - - public RMIRegistration(ComAdapter comAdapter) { - comAd = comAdapter; - } - - @Override - public void run() { - if (TRACE) { - System.out.println("LaunchRMIRegistry on Client on PORT " + ComAdapter.PORT); - } - try { - reg = java.rmi.registry.LocateRegistry.createRegistry(ComAdapter.PORT); - } - catch (Throwable e) { - if (TRACE) { - System.out.println("Registry notcreated !!" + e.getMessage()); - } - reg = null; - } - if (reg == null) { - if (TRACE) { - System.out.println("Try to get registry with getRegistry on PORT " + ComAdapter.PORT); - } - try { - reg = java.rmi.registry.LocateRegistry.getRegistry(ComAdapter.PORT); - } - catch (Throwable e) { - if (TRACE) { - System.out.println("registry not created !!" + e.getMessage()); - } - reg = null; - } - } - if (reg != null && TRACE) { - System.out.println("--> got RMIREGISTRY"); - } - comAd.setRMIRegistry(reg); - } - -} \ No newline at end of file diff --git a/src/eva2/tools/jproxy/JProxyRemoteThread.java b/src/eva2/tools/jproxy/JProxyRemoteThread.java deleted file mode 100644 index 36911d2f..00000000 --- a/src/eva2/tools/jproxy/JProxyRemoteThread.java +++ /dev/null @@ -1,107 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:29 $ - * $Author: ulmerh $ - */ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * - */ -public class JProxyRemoteThread implements InvocationHandler, Serializable { - private static ComAdapter m_ComAdapter; - private Object m_Object; - private RMIThreadInvocationHandler m_RMIThreadHandler; - private String m_ObjectName; - /** - * - */ - public static Object newInstance(Serializable object, String host) throws RMIServerNotAvailableException { - return Proxy.newProxyInstance( - object.getClass().getClassLoader(), - object.getClass().getInterfaces(), - new JProxyRemoteThread(object, host)); - } - - /** - * - */ - public static Object newInstance(Serializable object) throws RMIServerNotAvailableException { - return Proxy.newProxyInstance( - object.getClass().getClassLoader(), - object.getClass().getInterfaces(), - new JProxyRemoteThread(object)); - } - - /** - * - * @param c - * @return - */ - public static String[] getServerList() { - if (m_ComAdapter == null) { - //try { - m_ComAdapter = ComAdapter.getInstance(); -// } catch (NO_RMIServerAvailable ex) { -// ex.printStackTrace(); -// -// } - } - m_ComAdapter.evalAvailableHostNameList(); - return m_ComAdapter.getAvailableHostNameList(); - - } - - /** - * - */ - public static void setComAdaper(ComAdapter x) { - m_ComAdapter = x; - } - - - /** - * - */ - private JProxyRemoteThread(Serializable object, String host) throws RMIServerNotAvailableException { - if (m_ComAdapter == null) { - m_ComAdapter = ComAdapter.getInstance(); - } - m_RMIThreadHandler = m_ComAdapter.getRMIThreadHandler(object, host); - } - - /** - * - */ - private JProxyRemoteThread(Serializable object) throws RMIServerNotAvailableException { - if (m_ComAdapter == null) { - m_ComAdapter = ComAdapter.getInstance(); - } - m_RMIThreadHandler = m_ComAdapter.getRMIThreadHandler(object); - } - - /** - * - */ - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - Object ret = null; - if (method.getName().equals("getServerName")) { - ret = m_RMIThreadHandler.getServerName(); - } else { - ret = m_RMIThreadHandler.invoke(method.getName(), args); - } - - //long finish = System.currentTimeMillis(); - //System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start)); - return ret; - } -} diff --git a/src/eva2/tools/jproxy/MainAdapter.java b/src/eva2/tools/jproxy/MainAdapter.java deleted file mode 100644 index 548722c6..00000000 --- a/src/eva2/tools/jproxy/MainAdapter.java +++ /dev/null @@ -1,33 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:29 $ - * $Author: ulmerh $ - */ - -/** - * - */ -public interface MainAdapter { - - public String getExecOutput(String command); - - public void setBuf(String s); - - public void killServer(); - - public void restartServer(); - - public String getBuf(); - - public RMIInvocationHandler getRMIHandler(Object obj); - - public RMIThreadInvocationHandler getRMIThreadHandler(Object obj); - - public void setRemoteThis(MainAdapter x); -} - diff --git a/src/eva2/tools/jproxy/MainAdapterClient.java b/src/eva2/tools/jproxy/MainAdapterClient.java deleted file mode 100644 index fb1d9338..00000000 --- a/src/eva2/tools/jproxy/MainAdapterClient.java +++ /dev/null @@ -1,19 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ - -/** - * - */ -public interface MainAdapterClient { - public RMIInvocationHandler getRMIHandler(Object obj); - public RMIThreadInvocationHandler getRMIThreadHandler(Object obj); - public String getHostName(); -} diff --git a/src/eva2/tools/jproxy/MainAdapterClientImpl.java b/src/eva2/tools/jproxy/MainAdapterClientImpl.java deleted file mode 100644 index ce076836..00000000 --- a/src/eva2/tools/jproxy/MainAdapterClientImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ - -import java.net.InetAddress; -/** - * - */ -public class MainAdapterClientImpl implements MainAdapterClient { - static final public String MAIN_ADAPTER_CLIENT_NAME = "Main_Remote_Object_Client_Name"; - static public boolean TRACE = false; - private String m_HostName = "not__defined__"; - /** - * - */ - public MainAdapterClientImpl() { - try { - m_HostName = InetAddress.getLocalHost().getHostName(); - } catch (Exception e) { - System.out.println("ERROR getting HostName MainAdapterClientImpl "+e.getMessage()); - } - } - - /** - * - */ - public MainAdapterClientImpl(String hostName) { - m_HostName = hostName; - } - - /** - * - */ - @Override - public RMIInvocationHandler getRMIHandler(Object obj) { - if (TRACE) { - System.out.println("MainAdapterClientImpl.getRMIHandler"); - } - RMIInvocationHandler ret = null; - try { - ret = new RMIInvocationHandlerImpl(obj); - } catch (Exception e) { - System.out.println(" Error ret= new RMIInvokationHandlerImpl(obj);"+e.getMessage()); - } - return ret; - } - /** - * - */ - @Override - public RMIThreadInvocationHandler getRMIThreadHandler(Object obj) { - if (TRACE) { - System.out.println("MainAdapterClientImpl.getRMIThreadHandler"); - } - RMIThreadInvocationHandler ret = null; - try { - ret = new RMIThreadInvocationHandlerImpl(obj); - } catch (Exception e) { - System.out.println(" Error ret= new getRMIThreadHandler(obj);"+e.getMessage()); - } - return ret; - } - /** - * - */ - @Override - public String getHostName () { - return m_HostName; - } -} diff --git a/src/eva2/tools/jproxy/MainAdapterImpl.java b/src/eva2/tools/jproxy/MainAdapterImpl.java deleted file mode 100644 index 569925d5..00000000 --- a/src/eva2/tools/jproxy/MainAdapterImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - */ -public class MainAdapterImpl implements MainAdapter { - - private static final Logger LOGGER = Logger.getLogger(MainAdapterImpl.class.getName()); - public static final String MAIN_ADAPTER_NAME = "MainRemoteObjectName"; - public static final int PORT = 1099; - private String m_Buf = ""; - private MainAdapter remoteThis; - - /** - * - */ - public MainAdapterImpl() { - remoteThis = this; - } - - /** - * - */ - @Override - public void setBuf(String s) { - m_Buf = s; - } - - /** - * - */ - @Override - public void restartServer() { - LOGGER.log(Level.INFO, "Received a Message to restart the server."); - try { - String command = "java -cp . eva2.server.EvAServer &"; - - LOGGER.log(Level.INFO, "Calling the command:" + "java eva2.server.EvAServer"); - Process pro = Runtime.getRuntime().exec(command); - BufferedReader in = new BufferedReader(new InputStreamReader(pro.getInputStream())); - } catch (Exception ex) { - LOGGER.log(Level.WARNING, "Error while restarting the server.", ex); - } - killServer(); - } - - /** - * - */ - @Override - public void killServer() { - LOGGER.log(Level.INFO, "Received a Message to kill the server."); - KillThread x = new KillThread(); - x.start(); - } - - /** - * - */ - @Override - public String getBuf() { - return m_Buf; - } - - /** - * - */ - @Override - public String getExecOutput(String command) { - StringBuffer output = new StringBuffer(); - try { - BufferedReader in = null; - Process pro = null; - pro = Runtime.getRuntime().exec(command); - in = new BufferedReader(new InputStreamReader(pro.getInputStream())); - String line = null; - while ((line = in.readLine()) != null) { - output.append(line); - } - } catch (Exception e) { - System.err.println("Error in calling the command:" + e.getMessage()); - } - return output.toString(); - } - - /** - * - */ - @Override - public RMIInvocationHandler getRMIHandler(Object obj) { - System.out.println("getRMIHandler"); - RMIInvocationHandler ret = null; - try { - ret = new RMIInvocationHandlerImpl(obj); - } catch (Exception e) { - System.out.println("Error: RMIInvokationHandler getRMIHandler"); - } - return ret; - } - - /** - * - */ - @Override - public RMIThreadInvocationHandler getRMIThreadHandler(Object obj) { - RMIThreadInvocationHandler ret = null; - try { - - ret = new RMIThreadInvocationHandlerImpl(obj); - } catch (Exception e) { - System.out.println("Error: RMIThreadInvokationHandler getRMIThreadHandler"); - } - return ret; - } - - /** - * - */ - @Override - public void setRemoteThis(MainAdapter x) { - remoteThis = x; - } -} - -/** - * - */ -class KillThread extends Thread { - - /** - * - */ - @Override - public void run() { - try { - sleep(3000); - } catch (Exception e) { - System.out.println("Error in sleep"); - } - System.exit(-1); - } -} diff --git a/src/eva2/tools/jproxy/RMIConnection.java b/src/eva2/tools/jproxy/RMIConnection.java deleted file mode 100644 index 9d5e24f4..00000000 --- a/src/eva2/tools/jproxy/RMIConnection.java +++ /dev/null @@ -1,99 +0,0 @@ -package eva2.tools.jproxy; - - -/** - * - */ -public class RMIConnection { - public static boolean TRACE = false; - private String m_HostName; - protected MainAdapter m_MainAdapter; - protected MainAdapterClient m_MainAdapterClient; - /** - * - */ - public RMIConnection(String HostName, MainAdapter Adapter, - MainAdapterClient AdapterClient) { - m_MainAdapter = Adapter; - m_HostName = HostName; - m_MainAdapterClient = AdapterClient; - } - - /** - * - */ - public String getHostName() { - return m_HostName; - } - - /** - * - */ - public MainAdapter getMainAdapter() { - return m_MainAdapter; - } - - /** - * - */ - public void killServer() { - try { - m_MainAdapter.killServer(); - } catch (Exception e) { - System.out.println("Error while killing server: " + e.getMessage()); - } - } - - /** - * - */ - public void restartServer() { - try { - m_MainAdapter.restartServer(); - } catch (Exception e) { - System.out.println("Error while restartServer server: " + e.getMessage()); - } - } - - /** - * - */ - public RMIInvocationHandler getRMIHandler(Object c) { - RMIInvocationHandler ret = null; - try { - ret = m_MainAdapter.getRMIHandler(c); - } catch (Exception e) { - System.out.println("Error while getRMIHandler server: " + e.getMessage()); - e.printStackTrace(); - } - return ret; - } - - /** - * - */ - public RMIThreadInvocationHandler getRMIThreadHandler(Object c) { - RMIThreadInvocationHandler ret = null; - try { - ret = m_MainAdapter.getRMIThreadHandler(c); - } catch (Exception e) { - System.err.println("Error while RMIThreadInvokationHandler server: " + - e.getMessage()); - e.printStackTrace(); - } - return ret; - } - - /** - * - */ - public String getExecOutput(String command) { - String ret = null; - try { - ret = m_MainAdapter.getExecOutput(command); - } catch (Exception e) { - System.out.println("Error while getExecOutput server: " + e.getMessage()); - } - return ret; - } -} diff --git a/src/eva2/tools/jproxy/RMIInvocationHandler.java b/src/eva2/tools/jproxy/RMIInvocationHandler.java deleted file mode 100644 index 26c5503e..00000000 --- a/src/eva2/tools/jproxy/RMIInvocationHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ - -import java.rmi.Remote; -import java.rmi.RemoteException; -/*==========================================================================* -* INTERFACE DECLARATION -*==========================================================================*/ -/** - * - */ -public interface RMIInvocationHandler extends Remote { - public Object invoke (String m, Object[] args)throws RemoteException; - public Object getWrapper () throws RemoteException; - public void setWrapper(Object Wrapper) throws RemoteException; -} \ No newline at end of file diff --git a/src/eva2/tools/jproxy/RMIInvocationHandlerImpl.java b/src/eva2/tools/jproxy/RMIInvocationHandlerImpl.java deleted file mode 100644 index 32dbcea4..00000000 --- a/src/eva2/tools/jproxy/RMIInvocationHandlerImpl.java +++ /dev/null @@ -1,147 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/07/31 20:02:09 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ - -import eva2.tools.math.RNG; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -/*==========================================================================* -* CLASS DECLARATION -*==========================================================================*/ -/** - * - */ -public class RMIInvocationHandlerImpl extends UnicastRemoteObject implements RMIInvocationHandler { - public static final boolean TRACE = false; - private Object m_Object; - private String m_AdapterName; - private Object m_Wrapper; - private Method[] m_list;// m_Object.getClass().getMethods(); - /** - * - */ - public RMIInvocationHandlerImpl(Object obj) throws RemoteException { - if (TRACE) { - System.out.println("RMIInvokationHandlerImpl"); - } - m_AdapterName = obj.getClass().getName()+"_"+RNG.randomInt(0,10000); - try { - m_Object = obj; - m_list = m_Object.getClass().getMethods(); - if (TRACE) { - System.out.println(" --> rebind : "+m_AdapterName+" RMIInvokationHandlerImpl of object "+obj.getClass().getName()); - } - Naming.rebind(m_AdapterName,this); - } catch (Exception e) { - System.err.println(" Naming.rebind --> ERROR" + e.getMessage()); - e.printStackTrace(); - } - } - /** - * - */ - public RMIInvocationHandlerImpl(Object obj,String AdapterName) throws RemoteException { - m_AdapterName = AdapterName; - try { - m_Object = obj; - m_list = m_Object.getClass().getMethods(); - if (TRACE) { - System.out.println(" -----> rebind : "+m_AdapterName+" "+this.getClass().getName()+" of object "+obj.getClass().getName()); - } - Naming.rebind(m_AdapterName,this); - } catch (Exception e) { - System.err.println(" Naming.rebind --> ERROR " + obj + " " + e.getMessage()); - e.printStackTrace(); - } - } - /** - * - */ - @Override - public void setWrapper(Object Wrapper) throws RemoteException { - m_Wrapper = Wrapper; - } - /** - * - */ - @Override - public Object getWrapper () throws RemoteException { - return m_Wrapper; - } - - /** - * - */ - @Override - public Object invoke (String m, Object[] args) throws RemoteException { - Object ret=null; - String Name = ""; - //System.out.println("calling "+m); - if (TRACE) { - Name = Thread.currentThread().getName(); - } - try { - if (TRACE) { - System.out.println( Name+" Before invoke on server :" +m); - } - //Method[] list = m_Object.getClass().getMethods(); - boolean invoked = false; - for (int i=0;ilist :"+list.length); -// for (int j = 0; j < list.length; j++){ -// System.out.println("list="+list[j]+"--"+m_AdapterName); -// if (list[j].lastIndexOf(m_AdapterName)!=-1) { -// System.out.println("unbind !!!!!!!!!!!!!!!!!!!!!!!!!!"); -// Naming.unbind(list[j]); -// -// return null; -// } -// } -// System.out.println("Object not found !!!!!"); -// return null; -// } - if (m.equals(m_list[i].getName())==true) { - if (TRACE) { - System.out.println(Name+" find "+m); - } - //if (args==null) System.out.println(Name+" args==null "); - ret = m_list[i].invoke(m_Object,args); - invoked= true; - break; - } - } - if (invoked==false) { - System.out.println(Name+ " No memberfunction found !!!!!!!!!!!!!!!!!"); - } - } - catch ( InvocationTargetException e) { - e.printStackTrace(); - System.out.println(Name+" RMIInvokationHandlerImpl InvocationTargetException "+e.getMessage()); - } - catch (Exception e) { - e.printStackTrace(); - System.out.println(Name+" Exception :"+e.getMessage()); - } - return ret; - } -} diff --git a/src/eva2/tools/jproxy/RMIProxyLocal.java b/src/eva2/tools/jproxy/RMIProxyLocal.java deleted file mode 100644 index dbefc443..00000000 --- a/src/eva2/tools/jproxy/RMIProxyLocal.java +++ /dev/null @@ -1,123 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/04/15 12:28:34 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -/*==========================================================================* - * CLASS DECLARATION - *==========================================================================*/ -/** - * - */ -public class RMIProxyLocal implements InvocationHandler, Serializable { - private RMIInvocationHandler m_RMIHandler; - public static boolean TRACE = false; - private Class originalClass = null; - /** - * - */ - public static Object newInstance (Object c, String RMIName) { - if (TRACE) { - System.out.println("RMIProxyLocal:"+c.getClass().getName()); - } - RMIProxyLocal proxyLocal = new RMIProxyLocal(c,RMIName); - Object ret = java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - proxyLocal); - proxyLocal.setWrapper(ret); - proxyLocal.setOriginalClass(c.getClass()); - if (TRACE) { - System.out.println(" --> " + ret.getClass()); - } - return ret; - } - /** - * - */ - public static Object newInstance (Object c) { - if (TRACE) { - System.out.println("RMIProxyLocal:"+c.getClass().getName()); - } - RMIProxyLocal proxyLocal = new RMIProxyLocal(c); - Object ret = java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - proxyLocal); - proxyLocal.setWrapper(ret); - proxyLocal.setOriginalClass(c.getClass()); - if (TRACE) { - System.out.println(" --> " + ret.getClass()); - } - return ret; - } - /** - * - */ - private RMIProxyLocal (Object c) { - if (TRACE) { - System.out.println("RMIProxyLocal:"+c.getClass().getName()); - } - try { - m_RMIHandler = new RMIInvocationHandlerImpl(c); - } catch (Exception e) { - System.err.println("Error in m_RMIHandler = new RMIInvokationHandlerImpl(c)"); - e.printStackTrace(); - } - } - /** - * - */ - private RMIProxyLocal (Object c,String RMIName) { - try { - m_RMIHandler = new RMIInvocationHandlerImpl(c,RMIName); - } catch (Exception e) { - System.out.println("Error in m_RMIHandler = new RMIInvokationHandlerImpl(c)"); - e.printStackTrace(); - } - } - /** - * - */ - public void setWrapper(Object Wrapper) { - try { - m_RMIHandler.setWrapper(Wrapper); - } catch (Exception e) { - System.out.println("Error in setWrapper "+e.getMessage()); - } - } - - /** - * - */ - @Override - public Object invoke (Object proxy, Method m, Object[] args) throws Throwable { - return m_RMIHandler.invoke(m.getName(),args); - } - /** - * @return the originalClass - */ - public Class getOriginalClass() { - return originalClass; - } - /** - * @param originalClass the originalClass to set - */ - public void setOriginalClass(Class originalClass) { - if (TRACE) { - System.out.println("setting original proxy class "+originalClass.getName()); - } - this.originalClass = originalClass; - } -} diff --git a/src/eva2/tools/jproxy/RMIProxyLocalThread.java b/src/eva2/tools/jproxy/RMIProxyLocalThread.java deleted file mode 100644 index f1f558ab..00000000 --- a/src/eva2/tools/jproxy/RMIProxyLocalThread.java +++ /dev/null @@ -1,121 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - /*==========================================================================* - * CLASS DECLARATION - *==========================================================================*/ -/** - * - */ -public class RMIProxyLocalThread implements InvocationHandler,Serializable { - private RMIInvocationHandler m_RMIHandler; - private final static boolean TRACE = true; - /** - * - */ - public static Object newInstance (Object c,String RMIName) { - //System.out.println("RMIProxyLocal.newInstance !!!!!!!!!!!!!!!"); - RMIProxyLocalThread Proxy = new RMIProxyLocalThread(c,RMIName); - Object ret = java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - Proxy); - Proxy.setWrapper(ret); - if (TRACE) { - System.out.println("RMIProxyLocalThread "+c.getClass() + " ret " + ret.getClass()); - } - return ret; - } - /** - * - */ - public static Object newInstance (Object c) { - RMIProxyLocalThread Proxy = new RMIProxyLocalThread(c); - Object ret = java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - Proxy); - Proxy.setWrapper(ret); - if (TRACE) { - System.out.println("RMIProxyLocalThread "+c.getClass() + " ret " + ret.getClass()); - } - return ret; - } - /** - * - */ - private RMIProxyLocalThread (Object c) { - System.out.println("RMIProxyLocal:"+c.getClass().getName()); - try { - m_RMIHandler = new RMIInvocationHandlerImpl(ThreadProxy.newInstance(c)); - } catch (Exception e) { - System.out.println("Error in m_RMIHandler = new RMIInvokationHandlerImpl(c)"); - e.printStackTrace(); - } - } - /** - * - */ - private RMIProxyLocalThread (Object c,String RMIName) { - System.out.println("RMIProxyLocal:"+RMIName); - System.out.println("RMIProxyLocal:"+c.getClass().getName()); - - try { - m_RMIHandler = new RMIInvocationHandlerImpl(ThreadProxy.newInstance(c),RMIName); - } catch (Exception e) { - System.out.println("Error in m_RMIHandler = new RMIInvokationHandlerImpl(c)"); - e.printStackTrace(); - } - } - /** - * - */ - public void setWrapper(Object Wrapper) { - try { - m_RMIHandler.setWrapper(Wrapper); - } catch (Exception e) { - System.out.println("Error in setWrapper "+e.getMessage()); - } - } - - /** - * - */ - @Override - public Object invoke (Object proxy, Method m, Object[] args) throws Throwable { - //long start = System.currentTimeMillis(); - //System.out.println("Before invoke:" +m.getName()); - //Object ret = m_RMIHandler.invoke(m.getName(),args); - //long finish = System.currentTimeMillis(); - //System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start)); - //return ret; - return m_RMIHandler.invoke(m.getName(),args); - } - /** - * - */ - public static void main(String[] args) { - // - //Doit x = new DoitImpl(); -// Doit xx = (Doit) RMIProxyRemote.newInstance(x,"primergy4.informatik.uni-tuebingen.de"); -// Doit2 yy = (Doit2) RMIProxyLocal.newInstance(new Doit2Impl()); -// System.out.println(" jhdfjldf"); -// yy.doit(); -// yy.doit(); - -// xx.newdoit(yy); - } -} diff --git a/src/eva2/tools/jproxy/RMIProxyRemote.java b/src/eva2/tools/jproxy/RMIProxyRemote.java deleted file mode 100644 index 25938234..00000000 --- a/src/eva2/tools/jproxy/RMIProxyRemote.java +++ /dev/null @@ -1,125 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - /*==========================================================================* -* CLASS DECLARATION -*==========================================================================*/ -/** - * - */ - -public class RMIProxyRemote implements InvocationHandler,Serializable { - private static ComAdapter m_Adapter; - private static boolean TRACE = true; - private Object m_Object; - private String m_ObjectName; - private RMIInvocationHandler m_RMIHandler=null; - private long m_counter=0; - /** - * - */ - public static Object newInstance (Object c,MainAdapterClient Client) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemote(c,Client)); - } - /** - * - */ - public static Object newInstance (Object c,String host) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemote(c,host)); - } - /** - * - */ - public static Object newInstance (Object c) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemote(c)); - } - /** - * - */ - public static void setComAdaper(ComAdapter x) { - m_Adapter = x; - } - /** - * - */ - private RMIProxyRemote (Object c, String host) { - m_ObjectName = c.getClass().getName(); - if (m_Adapter==null) { - m_Adapter = ComAdapter.getInstance(); - } - m_RMIHandler = m_Adapter.getRMIHandler(c,host); - if (TRACE) { - System.out.println("creating RMIProxyRemote " + c.getClass() + " " + host); - } - } - /** - * - */ - private RMIProxyRemote (Object c, MainAdapterClient Client) { - m_ObjectName = c.getClass().getName(); - try { - m_RMIHandler = Client.getRMIHandler(c); - } catch (Exception e) { - System.out.println("RMIProxyRemote error ex "+e.getMessage()); - e.printStackTrace(); - } - if (TRACE) { - System.out.println("creating RMIProxyRemote " + c.getClass() + " " + Client.getClass()); - } - } - /** - * - */ - private RMIProxyRemote (Object c) { - m_ObjectName = c.getClass().getName(); - if (m_Adapter==null) { - m_Adapter = ComAdapter.getInstance(); - } - m_RMIHandler = m_Adapter.getRMIHandler(c); - } - /** - * - */ - @Override - public Object invoke (Object proxy, Method m, Object[] args) throws Throwable { - long start = System.currentTimeMillis(); - ++m_counter; - //System.out.println("Before invoke:" +m.getName()); - Object ret = m_RMIHandler.invoke(m.getName(),args); - long finish = System.currentTimeMillis(); - //System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start)); - return ret; - } - /** - * - */ -// public static void main(String[] args) { -// Doit remotex = (Doit) RMIProxyRemote.newInstance(new DoitImpl(),"primergy4.informatik.uni-tuebingen.de"); -// remotex.doit(); -// remotex.doit(); -// remotex.doit(); -// remotex.doit(); -// } -} diff --git a/src/eva2/tools/jproxy/RMIProxyRemoteThread.java b/src/eva2/tools/jproxy/RMIProxyRemoteThread.java deleted file mode 100644 index 35bc34f8..00000000 --- a/src/eva2/tools/jproxy/RMIProxyRemoteThread.java +++ /dev/null @@ -1,142 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/04/28 07:50:33 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -/*==========================================================================* -* CLASS DECLARATION -*==========================================================================*/ -/** - * - */ -public class RMIProxyRemoteThread implements InvocationHandler, - Serializable { - private static ComAdapter m_Adapter; - private RMIThreadInvocationHandler m_RMIThreadHandler; - /** - * - */ - public static Object newInstance (Object c,MainAdapterClient Client) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemoteThread(c,Client)); - } - /** - * - */ - public static Object newInstance (Object c,String host) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemoteThread(c,host)); - } - - private static void maybeLoadAdapter() { - if (m_Adapter==null) { - m_Adapter = ComAdapter.getInstance(); - } - } - - /** - * - * @param c - * @return - */ - public static String[] getServerList() { - maybeLoadAdapter(); - m_Adapter.evalAvailableHostNameList(); - return m_Adapter.getAvailableHostNameList(); - - } - public static void setServerList(String[] servers ) { - maybeLoadAdapter(); - - m_Adapter.setServerList(servers); - m_Adapter.evalAvailableHostNameList(); - - } - - /** - * - */ - public static Object newInstance (Object c) { - return java.lang.reflect.Proxy.newProxyInstance ( - c.getClass().getClassLoader(), - c.getClass().getInterfaces(), - new RMIProxyRemoteThread(c)); - } - /** - * - */ - public static void setComAdaper(ComAdapter x) { - m_Adapter = x; - } - /** - * - */ - private RMIProxyRemoteThread (Object c, String host) { -// m_ObjectName = c.getClass().getName(); - maybeLoadAdapter(); - m_RMIThreadHandler = m_Adapter.getRMIThreadHandler(c,host); - } - /** - * - */ - private RMIProxyRemoteThread (Object c, MainAdapterClient Client) { -// m_ObjectName = c.getClass().getName(); - try { - m_RMIThreadHandler = Client.getRMIThreadHandler(c); - } catch (Exception e) { - System.out.println("RMIProxyRemoteThreaderror ex "+e.getMessage()); - e.printStackTrace(); - } - } - /** - * - */ - private RMIProxyRemoteThread (Object c) { -// m_ObjectName = c.getClass().getName(); - maybeLoadAdapter(); - m_RMIThreadHandler = m_Adapter.getRMIThreadHandler(c); - } - /** - * - */ - @Override - public Object invoke (Object proxy, Method m, Object[] args) throws Throwable { - //long start = System.currentTimeMillis(); - //System.out.println("Before invoke:" +m.getName()); - Object ret = null; - if (m.getName().equals("getServerName")) { - ret = m_RMIThreadHandler.getServerName(); - } else { - ret = m_RMIThreadHandler.invoke(m.getName(), args); - } - //long finish = System.currentTimeMillis(); - //System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start)); - return ret; - } - /** - * - */ -// public static void main(String[] args) { -// Doit remotex = (Doit) RMIProxyRemoteThread.newInstance(new DoitImpl(), -// "ranode1.informatik.uni-tuebingen.de"); -// remotex.doit(); -// remotex.doit(); -// remotex.doit(); -// remotex.doit(); -// } -} diff --git a/src/eva2/tools/jproxy/RMIServer.java b/src/eva2/tools/jproxy/RMIServer.java deleted file mode 100644 index 69fc9779..00000000 --- a/src/eva2/tools/jproxy/RMIServer.java +++ /dev/null @@ -1,162 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:31 $ - * $Author: ulmerh $ - */ - -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.registry.Registry; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - */ -public class RMIServer { - /* - * Version string of the server application. - */ - - protected static RMIServer instance; - /* - * Name of host on which the server is running. - */ - private String myHostName = "undefined"; - /* - * IP of host on which the server is running. - */ - private String myHostIP = "undefined"; - /* - * MainAdapterImp object. This is need for the first connection between the server and the - * client program. - */ - protected MainAdapter mainRemoteObject; - /* - * String describing the properties of the enviroment. - */ -// private ComAdapter m_ComAdapter; - protected static String userName; - protected static int numberOfVM = 0; - private Registry myRegistry = null; - protected static final Logger LOGGER = Logger.getLogger(RMIServer.class.getName()); - - /** - * - */ - public static RMIServer getInstance() { - if (instance == null) { - instance = new RMIServer(); - } - return instance; - } - - /** - * Constructor of EvAServer. Calls RMIConnection(). - */ - protected RMIServer() { - userName = System.getProperty("user.name"); - initConnection(); - } - - /** - * Main method of this class. Is the starting point of the server application. - */ - public static void main(String[] args) { - LOGGER.log(Level.INFO, "Start RMIServer !"); - RMIServer application = RMIServer.getInstance(); - } - - /** - * Launches the RMIRegistry and makes the registration of the MainAdapterImpl class at the - * rmiregistry. - * - * @param - */ - private void initConnection() { - String mainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME; - System.setProperty("java.security.policy", "server.policy"); - launchRMIRegistry(); - try { - myHostIP = InetAddress.getLocalHost().getHostAddress(); - myHostName = InetAddress.getLocalHost().getHostName(); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Error getting HostName " + e.getMessage(), e); - } - LOGGER.log(Level.INFO, "Start of EvA RMI-Server on host " + myHostName + " = " + myHostIP); - - try { - String[] list = Naming.list("rmi://localhost:" + MainAdapterImpl.PORT); - numberOfVM = getNumberOfVM(list); - } catch (RemoteException e) { - LOGGER.log(Level.WARNING, "No RMI registry available yet"); - } catch (MalformedURLException ex) { - LOGGER.log(Level.SEVERE, "MalformedURLException: Error while looking up " + ex.getMessage(), ex); - } - createMainRemoteObject(mainAdapterName); - - LOGGER.log(Level.INFO, "End of RMI-Server Initialisation"); - LOGGER.log(Level.INFO, "Host: " + myHostName + " = " + myHostIP + ", adapter name is " + mainAdapterName); - LOGGER.log(Level.INFO, "Waiting for a client."); - } - - protected void createMainRemoteObject(String mainAdapterName) { - try { - mainRemoteObject = new MainAdapterImpl(); - mainRemoteObject = - (MainAdapter) RMIProxyLocal.newInstance(mainRemoteObject, mainAdapterName + "_" + numberOfVM); - mainRemoteObject.setRemoteThis(mainRemoteObject); - } catch (Exception ex) { - LOGGER.log(Level.WARNING, "Could not create main remote object!", ex); - } - } - - /** - * - */ - public MainAdapter getMainRemoteObject() { - return mainRemoteObject; - } - - /** - * Install RMIregistry on default port !! - */ - private void launchRMIRegistry() { - try { - myRegistry = java.rmi.registry.LocateRegistry.createRegistry(MainAdapterImpl.PORT); - } catch (Exception ex) { - myRegistry = null; - } - if (myRegistry == null) { - LOGGER.log(Level.INFO, "Try to get registry with getRegistry on port " + MainAdapterImpl.PORT); - try { - myRegistry = java.rmi.registry.LocateRegistry.getRegistry(MainAdapterImpl.PORT); - } catch (RemoteException e) { - myRegistry = null; - } - } - if (myRegistry == null) { - LOGGER.log(Level.WARNING, "Got no RMIREGISTRY"); - } - } - - /** - * - */ - private int getNumberOfVM(String[] list) { - int ret = 0; - for (int i = 0; i < list.length; i++) { - if (list[i].indexOf(MainAdapterImpl.MAIN_ADAPTER_NAME) != -1) { - ret++; - } - } - return ret; - } -} diff --git a/src/eva2/tools/jproxy/RMIServerNotAvailableException.java b/src/eva2/tools/jproxy/RMIServerNotAvailableException.java deleted file mode 100644 index d0d301d0..00000000 --- a/src/eva2/tools/jproxy/RMIServerNotAvailableException.java +++ /dev/null @@ -1,22 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ - -/** - * This exception will be thrown when no - * RMIServer can be found by the ComAdapter. - */ -public final class RMIServerNotAvailableException extends Exception { - - @Override - public String getMessage() { - return "There is no RMI Server available."; - } -} \ No newline at end of file diff --git a/src/eva2/tools/jproxy/RMIThreadInvocationHandler.java b/src/eva2/tools/jproxy/RMIThreadInvocationHandler.java deleted file mode 100644 index c8a09c43..00000000 --- a/src/eva2/tools/jproxy/RMIThreadInvocationHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:31 $ - * $Author: ulmerh $ - */ -import java.rmi.Remote; -import java.rmi.RemoteException; -/** - * - */ -public interface RMIThreadInvocationHandler extends Remote { - public Object invoke (String m, Object[] args)throws RemoteException; - public Object getWrapper () throws RemoteException; - public void setWrapper(Object Wrapper) throws RemoteException; - public String getServerName()throws RemoteException; -} \ No newline at end of file diff --git a/src/eva2/tools/jproxy/RMIThreadInvocationHandlerImpl.java b/src/eva2/tools/jproxy/RMIThreadInvocationHandlerImpl.java deleted file mode 100644 index 82de3a0f..00000000 --- a/src/eva2/tools/jproxy/RMIThreadInvocationHandlerImpl.java +++ /dev/null @@ -1,161 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/04/15 12:28:34 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import eva2.tools.math.RNG; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.InetAddress; -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; - -/*==========================================================================* -* CLASS DECLARATION -*==========================================================================*/ -/** - * - */ -public class RMIThreadInvocationHandlerImpl extends UnicastRemoteObject implements RMIThreadInvocationHandler { - public static final boolean TRACE = false; - private Object m_Object; - private String m_AdapterName; - private Object m_Wrapper; - private Method[] m_list; - private String m_hostname; - /** - * - * @return - */ - @Override - public String getServerName() { - return m_hostname; - } - /** - * - */ - public RMIThreadInvocationHandlerImpl(Object obj) throws RemoteException { - try { - m_hostname = InetAddress.getLocalHost().getHostName(); - } - catch (Exception e) { - System.out.println("ERROR getting HostName (RMIThreadInvokationHandlerImpl(obj))" + e.getMessage()); - } - - m_AdapterName = obj.getClass().getName()+"_"+RNG.randomInt(0,10000); - try { - m_Object = ThreadProxy.newInstance(obj); - m_list = m_Object.getClass().getMethods(); - if (TRACE) { - System.out.println(" --> rebind : "+m_AdapterName+" RMIThreadInvokationHandlerImpl of object "+obj.getClass().getName()); - } - Naming.rebind(m_AdapterName,this); - } catch (Exception e) { - System.out.println(" Naming.rebind --> ERROR" + e.getMessage()); - e.printStackTrace(); - } - } - /** - * - */ - public RMIThreadInvocationHandlerImpl(Object obj,String AdapterName) throws RemoteException { - try { - m_hostname = InetAddress.getLocalHost().getHostName(); - } - catch (Exception e) { - System.out.println("ERROR getting HostName (RMIThreadInvokationHandlerImpl(obj,adapt))" + e.getMessage()); - } - - m_AdapterName = AdapterName; - try { - m_Object = ThreadProxy.newInstance(obj); - m_list = m_Object.getClass().getMethods(); - if (TRACE) { - System.out.println(" -----> rebind : "+m_AdapterName+" "+this.getClass().getName()+" of object "+obj.getClass().getName()); - } - Naming.rebind(m_AdapterName,this); - } catch (Exception e) { - System.out.println(" Naming.rebind --> ERROR" + e.getMessage()); - } - } - /** - * - */ - @Override - public void setWrapper(Object Wrapper) throws RemoteException { - m_Wrapper = Wrapper; - } - /** - * - */ - @Override - public Object getWrapper () throws RemoteException { - return m_Wrapper; - } - /** - * - */ - @Override - public Object invoke (String m, Object[] args) throws RemoteException { - Object ret=null; - String Name = ""; - if (TRACE) { - Name = Thread.currentThread().getName(); - } - try { - if (TRACE) { - System.out.println( Name+" Before invoke on server :" +m); - } - //Method[] list = m_Object.getClass().getMethods(); - boolean invoked = false; - for (int i=0;ilist :" + list.length); - for (int j = 0; j < list.length; j++) { -// System.out.println("list=" + list[j] + "--" + m_AdapterName); - if (list[j].lastIndexOf(m_AdapterName) != -1) { -// System.out.println("unbind !!!!!!!!!!!!!!!!!!!!!!!!!!"); - Naming.unbind(list[j]); - return null; - } - - } - System.out.println("Object not found !!!!!"); - return null; - } - - if (m.equals(m_list[i].getName())==true) { - //if (TRACE)System.out.println(Name+" find "+m); - //if (args==null) System.out.println(Name+" args==null "); - ret = m_list[i].invoke(m_Object,args); - invoked= true; - break; - } - } - if (invoked==false) { - System.out.println(Name+ " No memberfunction found !!!!!!!!!!!!!!!!!"); - } - } - catch ( InvocationTargetException e) { - e.printStackTrace(); - System.out.println(Name+" RMIThreadInvokationHandlerImpl InvocationTargetException "+e.getMessage()); - } - catch (Exception e) { - e.printStackTrace(); - System.out.println(Name+" Exception :"+e.getMessage()); - } - return ret; - } -} diff --git a/src/eva2/tools/jproxy/RemoteStateListener.java b/src/eva2/tools/jproxy/RemoteStateListener.java deleted file mode 100644 index 36f956b0..00000000 --- a/src/eva2/tools/jproxy/RemoteStateListener.java +++ /dev/null @@ -1,20 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.1 $ - * $Date: 2004/04/15 09:12:30 $ - * $Author: ulmerh $ - */ - -/** - * - */ -public interface RemoteStateListener { - public void performedStop(); - public void performedStart(String infoString); - public void performedRestart(String infoString); - public void updateProgress(final int percent, String msg); -} diff --git a/src/eva2/tools/jproxy/ThreadProxy.java b/src/eva2/tools/jproxy/ThreadProxy.java deleted file mode 100644 index 75308e38..00000000 --- a/src/eva2/tools/jproxy/ThreadProxy.java +++ /dev/null @@ -1,98 +0,0 @@ -package eva2.tools.jproxy; -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/04/28 07:50:33 $ - * $Author: ulmerh $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -/*==========================================================================* - * CLASS DECLARATION - *==========================================================================*/ -/** - * - */ -public class ThreadProxy implements InvocationHandler, - Serializable { - private Object m_Object; - private ThreadWrapper m_ThreadWrapper; - private int m_maxthreads = 8; - /** - * - */ - public static Object newInstance (Object obj) { - return Proxy.newProxyInstance( - obj.getClass().getClassLoader(), - obj.getClass().getInterfaces(), - new ThreadProxy(obj)); - } - /** - * - */ - public static Object newInstance (Object obj,int maxthreads) { - return Proxy.newProxyInstance( - obj.getClass().getClassLoader(), - obj.getClass().getInterfaces(), - new ThreadProxy(obj,maxthreads)); - } - - /** - * - */ - public ThreadProxy (Object obj) { - m_Object = obj; - } - /** - * - */ - public ThreadProxy (Object obj,int maxthreads) { - m_Object = obj; - m_maxthreads = maxthreads; - } - - /** - * - */ - @Override - public Object invoke (Object proxy,Method method,Object[] args) throws Throwable { - Class rettype = method.getReturnType(); - if (rettype.equals(Void.TYPE)== true) { - if (m_ThreadWrapper == null) { - m_ThreadWrapper = new ThreadWrapper(m_maxthreads); - } - else { - m_ThreadWrapper.pleasewait(); - } - m_ThreadWrapper.invoke(m_Object,method,args); - return null; - } - Object ret = null; - try { - if (method.getName().equals("isAlive")) { - - if (m_ThreadWrapper != null) { - Boolean rret = new Boolean(m_ThreadWrapper.isAlive()); - // System.out.println("calling is alive" +rret); - return rret; - } - } - if (m_ThreadWrapper != null) { - m_ThreadWrapper.pleasewait(); - } - ret = method.invoke(m_Object, args); - } catch (Exception e) { - System.out.println("ERROR +" + e.getMessage()); - e.printStackTrace(); - } - return ret; - } -} diff --git a/src/eva2/tools/jproxy/ThreadWrapper.java b/src/eva2/tools/jproxy/ThreadWrapper.java deleted file mode 100644 index b872f46a..00000000 --- a/src/eva2/tools/jproxy/ThreadWrapper.java +++ /dev/null @@ -1,76 +0,0 @@ -package eva2.tools.jproxy; - -/** - * Title: The JProxy Framework - * Description: API for distributed and parallel computing. - * Copyright: Copyright (c) 2004 - * Company: University of Tuebingen - * @version: $Revision: 1.2 $ - * $Date: 2004/04/28 07:50:33 $ - * $Author: ulmerh $ - */ - -import java.lang.reflect.Method; -import java.util.ArrayList; - -public class ThreadWrapper extends ArrayList { - private int m_counter = 0; - private ArrayList m_ThreadContainer = new ArrayList(); - private static int m_numberofMAXThreads = 4; - /** - * - */ - public ThreadWrapper(int number) { - m_numberofMAXThreads = number; - } - - /** - * - */ - public ThreadWrapper() { - } - - /** - * - */ - public synchronized void invoke(Object x, String Method, Object[] Para) { - m_ThreadContainer.add(XThread.getXThread(x, Method, Para, m_numberofMAXThreads)); -// System.out.println("ADDED to THREADWRAPPER LIST" + m_ThreadContainer.size()); - } - - /** - * - */ - public synchronized void invoke(Object x, Method m, Object[] Para) { - m_ThreadContainer.add(XThread.getXThread(x, m, Para, m_numberofMAXThreads)); -// System.out.println("ADDED to THREADWRAPPER LIST" + m_ThreadContainer.size()); - } - - /** - * - */ - public synchronized void pleasewait() { - for (int i = 0; i < m_ThreadContainer.size(); i++) { - try { - ((Thread) m_ThreadContainer.get(i)).join(); - m_ThreadContainer.remove(i); // testhu - } catch (InterruptedException e) { - e.printStackTrace(); - System.out.println("Error"); - } - } - } - - /** - * - */ - public synchronized boolean isAlive() { - for (int i = 0; i < m_ThreadContainer.size(); i++) { - boolean alive = ((Thread) m_ThreadContainer.get(i)).isAlive(); - if (alive == true) { - return true; - } - } - return false; - } -} diff --git a/src/eva2/tools/jproxy/XThread.java b/src/eva2/tools/jproxy/XThread.java deleted file mode 100644 index 0fabdb19..00000000 --- a/src/eva2/tools/jproxy/XThread.java +++ /dev/null @@ -1,204 +0,0 @@ -package eva2.tools.jproxy; - -import java.io.Serializable; -import java.lang.reflect.Method; - -/* - * ==========================================================================* - * CLASS DECLARATION - * ========================================================================== - */ -public class XThread extends Thread implements Serializable { - private Object m_Object; - private volatile Method m_Method; - private volatile Object[] m_Para; - //private static byte m_instances = 0; - private static XThread[] m_Instances; - private static int m_MAXinstances = 10; - private static int m_index = 0; - - public static void init(int x) { - m_MAXinstances = x; - m_Instances = new XThread[m_MAXinstances]; - m_index = 0; - } - -// private static void instup() { -// m_instances++; -// } -// -// private static void instdown() { -// m_instances--; -// } - - public static int get() { - int ret =0; - if (m_Instances==null) { - return ret; - } - for (int i=0;i= m_Instances.length) { - m_index = 0; - } - if (m_Instances[m_index] == null) { - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - } - int w = 1; - while (true) { - for (int i = 0; i < m_Instances.length; i++) { - if (m_Instances[i] == null) { - m_index = i; - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - } - if (m_Instances[i].isAlive() == false) { - m_index = i; - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - - } - } - try { - Thread.sleep(w); - w = 2 * w; //System.out.println(""+i); - } catch (Exception e) { - System.err.println("Error in sleep of XThread"); - } - - } // end of while true - } - - /** - * - */ - public static XThread getXThread(Object x, String m, Object[] Para, int MAXinstances) { - XThread ret = null; - if (m_Instances == null) { - init(MAXinstances); - } - if (m_index >= m_Instances.length) { - m_index = 0; - } - if (m_Instances[m_index] == null) { - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - } - int w = 1; - while (true) { - for (int i = 0; i < m_Instances.length; i++) { - if (m_Instances[i] == null) { - m_index = i; - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - } - if (m_Instances[i].isAlive() == false) { - m_index = i; - ret = new XThread(x, m, Para); - m_Instances[m_index] = ret; - m_index++; - return ret; - - } - } - try { - Thread.sleep(w); - w = 2 * w; //System.out.println(""+i); - } catch (Exception e) { - System.err.println("Error in sleep of XThread"); - } - - } // end of while true - - } - - private void removemyself() { - for (int i = 0; i < m_Instances.length; i++) { - if (this.m_Instances[i] == this) { - this.m_Instances[i] = null; - return; - } - } - System.err.println("DANGER!!!!!!!!! XTHREAD ->NOT<- REMOVED"); - } - /** - * - */ - private XThread(Object object, Method method, Object[] Para) { - m_Object = object; - m_Para = Para; - m_Method = method; - start(); - } - - /** - * - */ - private XThread(Object x, String method, Object[] Para) { - m_Object = x; - m_Para = Para; - try { - Method[] methods = x.getClass().getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(method) == true) { - m_Method = methods[i]; - break; - } - } - } catch (Exception e) { - System.err.println(" ERROR in XTHREAD +" + e.getMessage()); - e.printStackTrace(); - } - start(); - } - - /** - * - */ - @Override - public void run() { - if (m_Method != null) { - //setPriority(Thread.MAX_PRIORITY); - try { - m_Method.invoke(m_Object, m_Para); - } catch (Exception e) { - System.err.println("ERROR +" + e.getMessage()); - e.printStackTrace(); - } - } else { - System.err.println("Warning Method == null !!!!! in ThreadWrapper"); - } - removemyself(); - } - - -}