Package java.util

Examples of java.util.Vector


  /**
   *  Adapts the current configuration to the specified persistent server.
   */
  public void configure(A3CMLServer root) throws Exception {
    short rootid = root.sid;
    Vector toExplore = new Vector();

    // Temporary fix, reset visited and gateway fields
    reset();

    // Search alls directly accessible domains.
    for (Enumeration n = root.networks.elements(); n.hasMoreElements();) {
      A3CMLNetwork network = (A3CMLNetworkn.nextElement();

      A3CMLDomain domain = (A3CMLDomain) domains.get(network.domain);
      domain.gateway = rootid;
      domain.hops = 1;
      toExplore.addElement(domain);

      Log.logger.log(BasicLevel.DEBUG,
                     "configure - toExplore.add(" + domain + ")");
    }

    root.visited = true;
    root.gateway = -1;
    root.hops = 0;
    root.domain = "local";

    while (toExplore.size() > 0) {
      A3CMLDomain domain = (A3CMLDomain) toExplore.elementAt(0);
      toExplore.removeElementAt(0);
      A3CMLServer gateway = (A3CMLServer) servers.get(new Short(domain.gateway));

      if (Log.logger.isLoggable(BasicLevel.DEBUG))
        Log.logger.log(BasicLevel.DEBUG, "configure - explore(" + domain + ")");

      // Parse all nodes of this domain
      for (Enumeration s = domain.servers.elements();
      s.hasMoreElements();) {
        A3CMLServer server = (A3CMLServer) s.nextElement();

        if (server.visited) continue;

        if (Log.logger.isLoggable(BasicLevel.DEBUG))
          Log.logger.log(BasicLevel.DEBUG, "configure - explore(" + server + ")");

        server.visited = true;
        if (domain.gateway == rootid) {
          // The server is directly accessible from root
          server.gateway = -1;
          server.domain = domain.name;
        } else {
          server.gateway = domain.gateway;
          server.domain = gateway.domain;
        }
        server.hops = domain.hops;

        // If the server is a router then add the accessible domains
        // to the list.
        for (Enumeration n = server.networks.elements();
        n.hasMoreElements();) {
          A3CMLNetwork network = (A3CMLNetworkn.nextElement();
          A3CMLDomain d2 = (A3CMLDomain) domains.get(network.domain);

          if (Log.logger.isLoggable(BasicLevel.DEBUG))
            Log.logger.log(BasicLevel.DEBUG, "configure - parse(" + d2 + ")");

          if (d2 == domain) {
            if (Log.logger.isLoggable(BasicLevel.DEBUG))
              Log.logger.log(BasicLevel.DEBUG, "configure - setPort(" + network.port + ")");
            // The server is directly accessible from root server by
            // this network interface; fixes the communication port
            // for this server.

            // AF 03/11/2004 - It seems in fact the domain is the one we are
            // exploring, so if the server is directly accessible its listen
            // port is the one of this network...
            server.port = network.port;
            continue;
          }

          // If the domain is already explored then there is more
          // than one route to this domain.

          //if (d2.gateway != -1)
          // throw new Exception("more than one route to: " + domain);

          // if (d2.hops != -1)
          //             throw new Exception("more than one route to: " + domain);
          d2.hops = domain.hops +1;

          // The domain is not already explored.
          if (server.gateway == -1)
            d2.gateway = server.sid;   // the server is directly accessible
          else
            d2.gateway = server.gateway; // the server itself is routed
          toExplore.addElement(d2);

          if (Log.logger.isLoggable(BasicLevel.DEBUG))
            Log.logger.log(BasicLevel.DEBUG, "configure - toExplore.add(" + d2 + ")");
        }
      }
View Full Code Here


                     "Config.getDomainConfig(" + listDomainName + ")");

    Hashtable context = new Hashtable();

    A3CMLConfig domainConf = new A3CMLConfig();
    Vector domainList = new Vector();
    for (int i = 0; i < listDomainName.length; i++)
      domainList.addElement(listDomainName[i]);
   
    for (int n = 0; n < listDomainName.length; n++) {
      String domainName = listDomainName[n];

      // add domain "domainName" in domainConf.
      A3CMLDomain dom = getDomain(domainName).duplicate(context);
      domainConf.addDomain(dom);
     
      // add persistent server in domainConf.
      for (int i = 0; i < dom.servers.size(); i++) {
        A3CMLServer server = (A3CMLServer) dom.servers.elementAt(i);
        for (int j = 0; j < server.networks.size(); ) {
          A3CMLNetwork network = (A3CMLNetwork) server.networks.elementAt(j);
          if (!(network.domain.equals(AgentServer.ADMIN_DOMAIN) ||
                network.domain.equals("transient") ||
                domainList.contains(network.domain))) {
            server.networks.removeElement(network);
          } else
            j++;
        }
        domainConf.servers.put(new Short(server.sid),server);
      }
    }
     
    // add global properties in domainConf.
    for (Enumeration p = properties.elements(); p.hasMoreElements(); ) {
      A3CMLProperty property = (A3CMLProperty) p.nextElement();
      domainConf.addProperty(property.duplicate());
    }
   
    try {
      // for Admin Domain
      // add domain "ADMIN_DOMAIN" in domainConf.
      A3CMLDomain d0 = getDomain(AgentServer.ADMIN_DOMAIN);
      domainConf.addDomain(new A3CMLDomain(d0.name,d0.network));
      A3CMLServer s0 = domainConf.getServer(AgentServer.getServerId());
      d0 = domainConf.getDomain(AgentServer.ADMIN_DOMAIN);
      d0.addServer(s0);
      for (int i = 0; i < s0.networks.size(); ) {
        A3CMLNetwork network = (A3CMLNetwork) s0.networks.elementAt(i);
        if (!(network.domain.equals(AgentServer.ADMIN_DOMAIN) ||
              domainList.contains(network.domain))) {
          s0.networks.removeElement(network);
        } else
          i++;
      }
    } catch (UnknownServerException exc) {
View Full Code Here

    if ((name == null) || (name.length() == 0))
      this.name = "server" + sid;
    else
      this.name = name;
    this.hostname = hostname;
    this.services = new Vector();
    this.networks = new Vector();
  }
View Full Code Here

        // assert that message is queued as we have no key
        Util.assertTrue(observer.getUpMessages().isEmpty());

        // send a view change to trigger the become key server
        // we use the fact that our address is now the controller one
        Vector tempVector=new Vector();
        tempVector.add(tempAddress);
        View tempView=new View(new ViewId(tempAddress, 1), tempVector);
        Event event=new Event(Event.VIEW_CHANGE, tempView);
        // this should have changed us to the key server
        encrypt.up(event);
View Full Code Here

        server.setObserver(serverObserver);
        Address serverAddress=new MockAddress("server");

        server.setLocal_addr(serverAddress);
        //set the server up as keyserver
        Vector serverVector=new Vector();
        serverVector.add(serverAddress);
        View tempView=new View(new ViewId(serverAddress, 1), serverVector);
        Event serverEvent=new Event(Event.VIEW_CHANGE, tempView);
        server.up(serverEvent);

        // set up peer
View Full Code Here

        //set the local address and view change to simulate a started instance
        Address serverAddress=new MockAddress("server");
        server.setLocal_addr(serverAddress);

        //  set the server up as keyserver
        Vector serverVector=new Vector();
        serverVector.add(serverAddress);
        View tempView=new View(new ViewId(serverAddress, 1), serverVector);
        Event serverEvent=new Event(Event.VIEW_CHANGE, tempView);
        server.up(serverEvent);

        // set up peer as if it has started but not recieved view change
        Address peerAddress=new MockAddress("peer");
        peer.setLocal_addr(peerAddress);
        MockObserver peerObserver=new MockObserver();
        peer.setObserver(peerObserver);
        peer.keyServer=false;

        // set up peer2 with server as key server
        Address peer2Address=new MockAddress("peer2");
        peer2.setLocal_addr(peer2Address);
        MockObserver peer2Observer=new MockObserver();
        peer2.setObserver(peer2Observer);
        peer2.keyServer=false;
        peer2.setKeyServerAddr(serverAddress);

        // send an encrypted message from the server
        Message msg=new Message();
        msg.setBuffer("hello".getBytes());


        Event evt=new Event(Event.MSG, msg);

        server.down(evt);

        // message0 is in response to view change
        Event encEvt=(Event)serverObserver.getDownMessages().get("message1");

        // sent to peer encrypted - should be queued in encyption layer as we do not have a keyserver set
        peer.up(encEvt);

        //assert that message is queued as we have no key from server
        Util.assertTrue(peerObserver.getUpMessages().isEmpty());

        // send a view change to peer where peer2 is  controller
        Vector peerVector=new Vector();
        peerVector.add(peer2Address);
        View tempPeerView=new View(new ViewId(peer2Address, 1), peerVector);
        Event event=new Event(Event.VIEW_CHANGE, tempPeerView);

        // send to peer - should set peer2 as keyserver
        peer.up(event);

        // assert that peer\ keyserver address is now set
        Util.assertEquals(peer2Address, peer.getKeyServerAddr());

        // get the resulting message from the peer - should be a key request to peer2
        Event sent=(Event)peerObserver.getDownMessages().get("message0");

        // ensure type and that request contains peers pub key
        Util.assertEquals(((EncryptHeader)((Message)sent.getArg()).getHeader(ENCRYPT_ID)).getType(), EncryptHeader.KEY_REQUEST);
        Util.assertEquals(new String(((Message)sent.getArg()).getBuffer()), new String(peer.getKpair().getPublic().getEncoded()));

        //assume that server is no longer available and peer2 is new server
        // but did not get the key from server before assuming role
        // send this event to peer2
//     send a view change to trigger the become key server
        // we use the fact that our address is now the controller one
        // send a view change where we are not the controller
        Vector peer2Vector=new Vector();
        peer2Vector.add(peer2Address);
        View tempPeer2View=new View(new ViewId(peer2Address, 1), peer2Vector);
        Event event2=new Event(Event.VIEW_CHANGE, tempPeer2View);
        // this should have changed us to the key server
        peer2.up(event2);
View Full Code Here

                 "ReliableTcpConnection.windowSize=" + windowSize);
    timer = timer2;
    inputCounter = -1;
    outputCounter = 0;
    unackCounter = 0;
    pendingMessages = new Vector();
    inputLock = new Object();
    outputLock = new Object();
   
    setStatus(INIT);
  }
View Full Code Here

    this.params = params;
    this.reconnect = reconnect;
    if (params.cnxPendingTimer > 0)
      this.reconnectTimeout = Math.max(2*params.cnxPendingTimer,
                                       (params.connectingTimer*1000)+params.cnxPendingTimer);
    addresses = new Vector();
    key = -1;
    this.identity = identity;

    setStatus(INIT);
  }
View Full Code Here

            MethodCall call = new MethodCall("innerMethod", new Object[0], new Class[0]);
            // RspList rspList = disp.callRemoteMethods(null, call, GroupRequest.GET_ALL, 5000);
            RequestOptions opts=new RequestOptions(GroupRequest.GET_ALL, 0, false, null, (byte)0);
            opts.setFlags(Message.OOB);
            RspList rspList = disp.callRemoteMethods(null, call, opts);
            Vector results = rspList.getResults();
            log("results of calling innerMethod():\n" + rspList);
            StringBuilder sb=new StringBuilder("outerMethod[");
            for(Enumeration e = results.elements(); e.hasMoreElements(); ) {
                String s = (String)e.nextElement();
                sb.append(s);
                if (e.hasMoreElements()) {
                    sb.append(";");
                }
View Full Code Here


    /* ------------------------------- Interface MembershipListener ------------------------------ */

    public synchronized void viewAccepted(View new_view) {
        Vector joined_mbrs, left_mbrs, tmp;
        Object tmp_mbr;

        if(new_view == null) return;
        tmp=new_view.getMembers();

        synchronized(members) {
            // get new members
            joined_mbrs=new Vector();
            for(int i=0; i < tmp.size(); i++) {
                tmp_mbr=tmp.elementAt(i);
                if(!members.contains(tmp_mbr))
                    joined_mbrs.addElement(tmp_mbr);
            }

            // get members that left
            left_mbrs=new Vector();
            for(int i=0; i < members.size(); i++) {
                tmp_mbr=members.elementAt(i);
                if(!tmp.contains(tmp_mbr))
                    left_mbrs.addElement(tmp_mbr);
            }

            // adjust our own membership
            members.removeAllElements();
            members.addAll(tmp);
        }

        if(consumer != null) {
            if(!joined_mbrs.isEmpty())
                for(int i=0; i < joined_mbrs.size(); i++)
                    consumer.memberJoined((Address) joined_mbrs.elementAt(i));
            if(!left_mbrs.isEmpty())
                for(int i=0; i < left_mbrs.size(); i++)
                    consumer.memberLeft((Address) left_mbrs.elementAt(i));
        }
    }
View Full Code Here

TOP

Related Classes of java.util.Vector

Copyright © 2015 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.