1 4 5 package org.jfox.ioc.connector; 6 7 import java.io.Serializable ; 8 import java.rmi.RemoteException ; 9 10 18 19 public class ClusterableConnectorRemote extends AbstractConnectorRemote implements ConnectorRemote, Serializable { 20 21 private ConnectorRemote remote; 22 private ConnectorRemote[] clusterRemotes; 23 24 public ClusterableConnectorRemote(ConnectorRemote remote, ConnectorRemote[] clusterNodes) { 25 this.remote = remote; 26 this.clusterRemotes = clusterNodes; 27 } 28 29 38 public Object invoke(Invocation invocation) throws RemoteException , Exception { 39 Exception re = null; 40 try { 41 remote.ping(); 42 } 43 catch(Exception e){ re = e; 45 remote = null; 46 if(clusterRemotes != null && clusterRemotes.length >0){ 47 for(int i=0; i<clusterRemotes.length; i++){ 48 ConnectorRemote _remote = clusterRemotes[i]; 49 try { 50 _remote.ping(); 51 } 52 catch(Exception e1){ 53 e1.printStackTrace(); 54 continue; 55 } 56 remote = _remote; 57 } 58 } 59 } 60 if(remote == null){ 61 throw re; 62 } 63 invocation.setClustable(true); 64 Object result = remote.invoke(invocation); 65 return result; 66 } 67 68 public void ping() throws RemoteException { 69 remote.ping(); 70 } 71 72 public String getProtocol() throws RemoteException { 73 return remote.getProtocol(); 74 } 75 76 public ConnectorRemote getRemote() { 77 return remote; 78 } 79 80 84 protected void doStart() throws Exception { 85 } 86 87 protected void doStop() throws Exception { 88 } 89 90 protected void doInit() throws Exception { 91 } 92 93 protected void doDestroy() throws Exception { 94 } 95 96 97 public static void main(String [] args) { 98 99 } 100 } 101 | Popular Tags |