public class MessageReceiverFactory {
private static MessageReceiver messageReceiver;
private static RemotableMessageReceiver remotableMessageReceiver;
private static void init() throws ServerReceiverException {
SystemInfo sysInfo = ContextFactory.getSystemConfigContext()
.getSystemInfo();
if (sysInfo.isServer()) {
MessageReceiver mifMessageReceiver = new ServerMessageReceiver();
if (sysInfo.isRemoteable()) {
try {
remotableMessageReceiver = new RMIMessageReceiver(mifMessageReceiver);
} catch (RemoteException e) {
throw new ServerReceiverException(
"bind Message Receiver to port: "
+ sysInfo.getRmiport()
+ " with service name: "
+ sysInfo.getReceiverRmiBindName(), e);
}
}
messageReceiver = new StdMessageReceiver(mifMessageReceiver);
} else {
String rmiHost = sysInfo.getRmiHost();
int rmiPort = sysInfo.getRmiport();
String serviceName = sysInfo.getReceiverRmiBindName();
messageReceiver = createRemoteMesageReceiver(rmiHost, rmiPort,
serviceName);
}
}
public static MessageReceiver createRemoteMesageReceiver(String rmiHost,
int rmiPort, String serviceName) throws ServerReceiverException {
return new RemoteMessageReceiver(rmiHost, rmiPort, serviceName);
}
public synchronized static MessageReceiver getMessageReceiver() throws ServerReceiverException {
if(messageReceiver == null) {
init();
}
return messageReceiver;
}
public static RemotableMessageReceiver getRemoteableMesageReceiver(){
return remotableMessageReceiver;
}
public synchronized static void initMessageReceiver() throws ServerReceiverException {
init();
}
}
|