Package lupos.event.broker.distributed.model

Examples of lupos.event.broker.distributed.model.SubBrokerData


   * @return connection info to the free or least used broker
   */
  private TcpConnectInfo getProducerConnectBroker(){
   
    int temp = Integer.MAX_VALUE;
    SubBrokerData broker = null;
    for (SubBrokerData subBroker : this.subBrokers.values()){
      int size = subBroker.getRegisteredProducers().size();
      if(size<temp){
        temp = size;
        broker = subBroker; 
      }
    }
   
    return broker.getMessageService().getConnectionInfo();
  }
View Full Code Here


        }
        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
      }
     
    }
   
    else if (msg instanceof ModelUpdateMessage){
      TcpConnectInfo tcpInfo = ((SerializingMessageService)src).getConnectionInfo();
      SubBrokerData subBroker = null;
      for (SubBrokerData sub : this.subBrokers.values()){
        if (sub.getMessageService().getConnectionInfo().equals(tcpInfo)){
          subBroker = sub;
          break;
        }
      }
      if (subBroker != null){
        // update model of this sub broker
        ModelUpdateMessage message = (ModelUpdateMessage)msg;
        subBroker.setRegisteredProducers(message.getProducers());
        subBroker.setRegisteredConsumers(message.getConsumers());
        System.out.println("Recieved and stored update from SubBroker "+tcpInfo.getHost()+":"+tcpInfo.getPort());
      }
    }
  }
View Full Code Here

   * @return connection info for the broker with most producers and least consumers
   */
  private TcpConnectInfo getConsumerConnectBroker(){
    int tempProd = 0;
    int tempCons = Integer.MAX_VALUE;
    SubBrokerData broker = null;
    for (SubBrokerData subBroker : this.subBrokers.values()){
      int sizeCons = subBroker.getRegisteredConsumers().size();
      int sizeProd = subBroker.getRegisteredProducers().size();
      if((sizeCons<=tempCons && sizeProd>tempProd)||(sizeCons<tempCons && sizeProd>=tempProd)){
        tempCons = sizeCons;
        tempProd = sizeProd;
        broker = subBroker; 
      }
    }
   
    return broker.getMessageService().getConnectionInfo();
  }
View Full Code Here

      BrokerUpdateMessageCollector messageList = new BrokerUpdateMessageCollector();
     
      for(BConsumer curCon : regCon){
        int sum = 0;
        int ownSum = 0;
        SubBrokerData chosenBroker = null;
       
        for (SubBrokerData subBroker2 : this.subBrokers.values()){
          int tempSum=0;
          List<BProducer> regPro = subBroker2.getRegisteredProducers();
          for(BProducer curPro : regPro){
            for(String curConEvent : curCon.getWantedEvents()){
              if(curPro.getProducedEvent().equals(curConEvent)){
                if(!subBroker.equals(subBroker2)){
                  tempSum++;
                } else{
                  ownSum++;
                }
              }
            }
           
          }
          if(tempSum>sum){
            sum = tempSum;
            chosenBroker = subBroker2;
          }
        }
               
        if(sum>ownSum){
          BrokerUpdateMessage message = new BrokerUpdateMessage(chosenBroker.getMessageService().getConnectionInfo(),curCon);
          messageList.addMessage(message);
          System.out.println("Forwarded Consumer from "+subBroker.getMessageService().getConnectionInfo().getHost()
              +":"+subBroker.getMessageService().getConnectionInfo().getPort()+" to "
              +chosenBroker.getMessageService().getConnectionInfo().getHost()+":"
              +chosenBroker.getMessageService().getConnectionInfo().getPort());
        }
      }
      try {
        subBroker.getMessageService().sendMessage(messageList);
      } catch (IOException e) {
View Full Code Here

TOP

Related Classes of lupos.event.broker.distributed.model.SubBrokerData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.