}
@Override
public void messageReceived(Object src, Serializable msg) {
if (msg instanceof ConnectionRequest){
SerializingMessageService msgService = (SerializingMessageService) src;
msgService.setConnectionPort(((ConnectionRequest)msg).getPort());
switch (((ConnectionRequest) msg).getRequestType()){
case ConnectionRequest.REQUESTTYPE_PRODUCER:
TcpConnectInfo tcpInfo = getProducerConnectBroker();
try {
msgService.sendMessage(tcpInfo);
System.out.println("Producer redirected to "+tcpInfo.getHost()+":"+tcpInfo.getPort());
} catch (IOException e) {
e.printStackTrace();
}
break;
case ConnectionRequest.REQUESTTYPE_BROKER:
// put this sub broker in a hashtable
SubBrokerData subBroker = new SubBrokerData(msgService);
this.subBrokers.put(subBroker.getID(), subBroker);
subBroker.getMessageService().addDisconnectHandler(this);
System.out.println("Registered a SubBroker connection: "+msgService.getConnectionInfo().getHost()+":"+msgService.getConnectionInfo().getPort());
break;
case ConnectionRequest.REQUESTTYPE_CONSUMER:
TcpConnectInfo tcpInfo2 = getConsumerConnectBroker();
try {
msgService.sendMessage(tcpInfo2);
System.out.println("Consumer redirected to "+tcpInfo2.getHost()+":"+tcpInfo2.getPort());
} catch (IOException e) {
e.printStackTrace();
}
break;