📄 mafagentsystem_rmiclient.java
字号:
throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return null; } } /* synchronized */ private void rebind(RemoteException ex) throws RemoteException { /* * if (ex.detail instanceof java.io.IOException == false) { * ex.printStackTrace(); * String msg = ex.detail.getMessage(); * throw new RemoteException(msg,new MAFExtendedException(msg)); * } */ MAFAgentSystem_RMI new_rmi = Handler.rebind(_agent_system); if (new_rmi != null) { _agent_system = new_rmi; to_maf.put(new_rmi, this); } else { String msg = "ServerNotFound"; throw new RemoteException(msg, new MAFExtendedException(msg)); } } public void receive_agent(Name agent_name, AgentProfile agent_profile, byte[] agent, String place_name, ClassName[] class_names, String code_base, MAFAgentSystem class_sender) throws ClassUnknown, DeserializationFailed, MAFExtendedException /* RequestRefused */ { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; final AgentProfile fAgentProfile = agent_profile; final byte[] fAgent = agent; final String fPlaceName = place_name; final ClassName[] fClassNames = class_names; final String fCodeBase = code_base; final MAFAgentSystem fClassSender = class_sender; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { MAFAgentSystem_RMI rmi_class_sender = to_rmi_agentsystem(fClassSender); while (true) { try { fAgentSystem.receive_agent(fAgentName, fAgentProfile, fAgent, fPlaceName, fClassNames, fCodeBase, rmi_class_sender); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof ClassUnknown) { throw (ClassUnknown)ee.detail; } else if (ee.detail instanceof DeserializationFailed) { throw (DeserializationFailed)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } public long receive_future_message(Name agent_name, byte[] msg, MAFAgentSystem message_sender) throws AgentNotFound, MAFExtendedException { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; final byte[] fMsg = msg; final MAFAgentSystem fMessageSender = message_sender; Long result = (Long)AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { MAFAgentSystem_RMI rmi_message_sender = to_rmi_agentsystem(fMessageSender); while (true) { try { long r = fAgentSystem .receive_future_message(fAgentName, fMsg, rmi_message_sender); return new Long(r); } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); return result.longValue(); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return -1; } } public void receive_future_reply(long return_id, byte[] reply) throws EntryNotFound, MAFExtendedException { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final long fReturnID = return_id; final byte[] fReply = reply; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { fAgentSystem.receive_future_reply(fReturnID, fReply); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof EntryNotFound) { throw (EntryNotFound)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } public byte[] receive_message(Name agent_name, byte[] msg) throws AgentNotFound, NotHandled, MessageEx, MAFExtendedException { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; final byte[] fMsg = msg; return (byte[])AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { return fAgentSystem.receive_message(fAgentName, fMsg); } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof NotHandled) { throw (NotHandled)ee.detail; } else if (ee.detail instanceof MessageEx) { throw (MessageEx)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return null; } } public void receive_oneway_message(Name agent_name, byte[] msg) throws AgentNotFound, MAFExtendedException { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; final byte[] fMsg = msg; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { fAgentSystem.receive_oneway_message(fAgentName, fMsg); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } public void resume_agent(Name agent_name) throws AgentNotFound, ResumeFailed, AgentIsRunning { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { fAgentSystem.resume_agent(fAgentName); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof ResumeFailed) { throw (ResumeFailed)ee.detail; } else if (ee.detail instanceof AgentIsRunning) { throw (AgentIsRunning)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } public byte[] retract_agent(Name agent_name) throws AgentNotFound, MAFExtendedException { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; return (byte[])AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { return fAgentSystem.retract_agent(fAgentName); } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof MAFExtendedException) { throw (MAFExtendedException)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ex.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return null; } } public void setAddress(String name) { throw new NoSuchMethodError(); } public void suspend_agent(Name agent_name) throws AgentNotFound, SuspendFailed, AgentIsSuspended { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { fAgentSystem.suspend_agent(fAgentName); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof SuspendFailed) { throw (SuspendFailed)ee.detail; } else if (ee.detail instanceof AgentIsSuspended) { throw (AgentIsSuspended)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } public void terminate_agent(Name agent_name) throws AgentNotFound, TerminateFailed { try { final MAFAgentSystem_RMI fAgentSystem = _agent_system; final Name fAgentName = agent_name; AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws RemoteException { while (true) { try { fAgentSystem.terminate_agent(fAgentName); return null; } catch (ConnectException ex) { rebind(ex); } catch (UnmarshalException ex) { rebind(ex); } catch (MarshalException ex) { rebind(ex); } } } }); } catch (PrivilegedActionException ex) { RemoteException ee = (RemoteException)ex.getException(); if (ee.detail instanceof AgentNotFound) { throw (AgentNotFound)ee.detail; } else if (ee.detail instanceof TerminateFailed) { throw (TerminateFailed)ee.detail; } else if (ee.detail instanceof RuntimeException) { throw (RuntimeException)ee.detail; } else { ex.printStackTrace(); throw new RuntimeException(ee.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return; } } static MAFAgentSystem_RMI to_rmi_agentsystem(MAFAgentSystem __maf) { if (__maf instanceof MAFAgentSystem_RMIClient) { return ((MAFAgentSystem_RMIClient)__maf)._agent_system; } else { return MAFAgentSystem_RMIImpl.find_rmi_agentsystem(__maf); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -