Exemple #1
0
 @Override
 public boolean isSucceededBy(VectorTimeStamp other) {
   Tracer.info(this, "checking if this " + this + " is succeded by  " + other);
   Set<String> keys = contents.keySet();
   boolean foundOneSuccessor = false;
   for (String key : keys) {
     int myValue = get(key);
     int otherValue = other.get(key);
     int diff = otherValue - myValue;
     if (diff == 0) {
       Tracer.info(this, "Have received same number of messages from " + key);
       continue;
     } else if (diff != 1) {
       Tracer.info(this, "Have not received " + diff + " messages from " + key);
       return false;
     } else if (foundOneSuccessor) {
       Tracer.info(this, "Have not received 1 message from a second user " + key);
       return false;
     } else {
       Tracer.info(this, "Have not received 1 message from  " + key);
       foundOneSuccessor = true;
     }
   }
   return foundOneSuccessor;
 }
 @Override
 public void send(Set<String> clientNames, Object message) {
   if (clientNames.size() == 0) return;
   //		ByteBuffer message = bufferSerializationSupport.outputBufferFromSerializable(object);
   //		bbGroupServerInputPort.send(clientNames, message);
   //		if (message instanceof  ByteBuffer) {
   ////			bbGroupServerInputPort.send(clientNames, (ByteBuffer) message);
   //			Message.info(this, "Cannot send byte buffer on object port");
   //			return;
   //		}
   if (!(message instanceof Serializable)) {
     Tracer.info(this, "Can only send seralizable on object group port");
     return;
   }
   Tracer.info(this, "Sending group message:" + message + " to:" + clientNames);
   //		unOptimizedObjectForwarder.send(remoteName, message);
   //		if (bbGroupServerInputPort != null)
   //			sendOptimized(clientNames, message);
   //		else
   //			sendUnoptimized(clientNames, message);
   groupSendTrapper.send(clientNames, message);
   //		if (bbGroupServerInputPort != null)
   //			optimizedObjectForwarder.send(clientNames, message);
   //		else {
   //			for (String clientName:clientNames) {
   //				unOptimizedObjectForwarder.send(clientName, message);
   //			}
   //		}
 }
Exemple #3
0
 public boolean isConcurrent(VectorTimeStamp other) {
   //		if (other.size() != size()) {
   //			throw new RuntimeException("Incomparable vector time stamps: this:" + this + " other:" +
   // other );
   //		}
   Tracer.info(this, "Checking if this " + this + " is concurrent with " + other);
   Set<String> keys = contents.keySet();
   //		Set<String> otherKeys = other.users();
   //		keys.addAll(otherKeys);
   boolean otherGreater = false;
   boolean thisGreater = false;
   for (String key : keys) {
     int myValue = get(key);
     int otherValue = other.get(key);
     int diff = myValue - otherValue;
     if (diff == 0) {
       continue;
     } else if (diff > 0) {
       thisGreater = true;
       Tracer.info(this, "This has received " + diff + " additional messages from " + key);
       if (otherGreater) {
         Tracer.info(this, "The two time stamps are concurrent");
         return true;
       }
     } else {
       otherGreater = true;
       Tracer.info(this, "This has received " + -diff + " fewer messages from " + key);
       if (thisGreater) {
         Tracer.info(this, "The two time stamps are concurrent");
         return true;
       }
     }
   }
   return false;
 }
 public static void main(String[] args) {
   Tracer.showInfo(true);
   Tracer.setImplicitPrintKeywordKind(ImplicitKeywordKind.OBJECT_PACKAGE_NAME);
   Tracer.setMessagePrefixKind(MessagePrefixKind.FULL_CLASS_NAME);
   TraceableInfo.setPrintTraceable(true);
   TraceableInfo.setPrintSource(true);
   TraceableInfo.setPrintTime(true);
   TraceableInfo.setPrintThread(true);
   Tracer.setKeywordPrintStatus(ASimpleList.class, true);
   AnEchoComposerAndLauncher.traceUnawareLaunch(args);
 }
Exemple #5
0
  @Override
  public synchronized void join(
      String theClientName, ObjectReceiver theClient, String theApplicationName) {
    try {
      Tracer.info(this, "Entering Session Join");
      SessionJoinInformationUpdated.newCase(
          CommunicatorSelector.getProcessName(), theClientName, theApplicationName, myName, this);
      JoinInfo retVal = new JoinInfo();
      retVal.newSession = clients.size() == 0;
      ProcessGroup processGroupRemote = multicastGroups.get(theApplicationName);
      ProcessGroupLocal procesGroupLocal = localProcessGroups.get(theApplicationName);
      retVal.newApplication = processGroupRemote == null;

      if (processGroupRemote == null) {
        MulticastGroupCreated.newCase(CommunicatorSelector.getProcessName(), myName, this);
        AProcessGroup processGroup = new AProcessGroup(myName, theApplicationName, null);
        procesGroupLocal = processGroup;
        addSessionListenerLocal(procesGroupLocal);
        processGroupRemote = (ProcessGroup) UnicastRemoteObject.exportObject(processGroup, 0);
        multicastGroups.put(theApplicationName, processGroupRemote);
        localProcessGroups.put(theApplicationName, procesGroupLocal);
      }
      clients.put(theClient, theClientName);
      addSessionListener(theClient);
      notifyClientJoinedRemote(
          processGroupRemote,
          toSerializedProcesstGroups(),
          clients,
          myName,
          theClientName,
          theClient,
          theApplicationName,
          retVal.newSession,
          retVal.newApplication);
      notifyClientJoinedLocal(
          procesGroupLocal,
          toSerializedProcesstGroups(),
          clients,
          myName,
          theClientName,
          theClient,
          theApplicationName,
          retVal.newSession,
          retVal.newApplication);
      Tracer.info(this, "Leaving Session Join");
      // why was this commented out?
      ServerClientJoined.newCase(
          CommunicatorSelector.getProcessName(), theClientName, theApplicationName, myName, this);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }
  public static PredictionValueToStatus newCase(String aMessage, Object aFinder) {
    if (Tracer.isPrintInfoEnabled(aFinder)
        || Tracer.isPrintInfoEnabled(PredictionValueToStatus.class))
      EventLoggerConsole.getConsole()
          .getMessageConsoleStream()
          .println("(" + Tracer.infoPrintBody(PredictionValueToStatus.class) + ") " + aMessage);
    if (shouldInstantiate(PredictionValueToStatus.class)) {
      PredictionValueToStatus retVal = new PredictionValueToStatus("", aFinder);
      retVal.announce();
      return retVal;
    }
    Tracer.info(aFinder, aMessage);

    return null;
  }
 @Override
 public void send(String clientName, InMessageType message) {
   Tracer.info(this, "Converting single to multiple send");
   Set<String> clientNames = new HashSet();
   clientNames.add(clientName);
   send(clientNames, message);
 }
Exemple #8
0
 public synchronized void paintShapes(Graphics g) {
   try {
     // System.out.println("slModel " + slModel);
     List sortedShapes = new ArrayList(slModel.getSortedList());
     //        System.out.println("Painting:" + sortedShapes);
     // for (Enumeration shapeModels = slModel.elements();shapeModels.hasMoreElements();)
     for (int index = sortedShapes.size() - 1; index >= 0; index--) {
       // System.out.println("paintShapes " + this);
       // RemoteShape shapeModel = (RemoteShape) shapeModels.nextElement();
       if (index >= sortedShapes.size()) {
         Tracer.error("Index, " + index + ">=  size:" + sortedShapes.size() + " of sorted shapes");
       }
       RemoteShape shapeModel = (RemoteShape) sortedShapes.get(index);
       if ((mouseController == null) || mouseController.notBuffered(shapeModel)) {
         // System.out.println("paintShape " + this);
         /*
         if (shapeModel == selectedShape)
          paintSelection(g);
         else
         */
         paintShape(g, shapeModel, container);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void messageReceived(String aSourceName, Object aMessage) {
   Tracer.info(this, "message Received:" + aMessage);
   //		System.out.println("Message:" + aMessage);
   String oldOutput = output;
   MessageWithSource messageWithSource = (MessageWithSource) aMessage;
   output = (String) messageWithSource.getMessage();
   propertyChangeSupport.firePropertyChange(
       new PropertyChangeEvent(this, "output", oldOutput, output));
 }
 @Override
 public void send(String clientName, Object message) {
   Tracer.info(this, this + "  serializing message " + message + " to " + clientName);
   try {
     ByteBuffer bbMessage = bufferSerializationSupport.outputBufferFromObject(message);
     destination.send(clientName, bbMessage);
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public static void launchTypedIPClient(String clientName) {
    Tracer.showInfo(true);
    SimplexClientInputPort<Object> clientInputPort =
        SimplexObjectInputPortSelector.createSimplexClientInputPort(
            "localhost", "9090", "test server", clientName);
    PrintingTypedReceiveListener printingTypedReceiveListener =
        new PrintingTypedReceiveListener(clientInputPort);
    clientInputPort.addConnectionListener(printingTypedReceiveListener);
    //		clientInputPort.addDisconnectListener(printingTypedReceiveListener);
    //		clientInputPort.addReceiveListener(printingTypedReceiveListener);
    //		clientInputPort.addReceiveListener(printingTypedReceiveListener);
    clientInputPort.addSendListener(printingTypedReceiveListener);

    clientInputPort.connect();
    //		ByteBuffer message =  ByteBuffer.wrap("hello server".getBytes());
    //		System.out.println("String with padding:" + new String(message.array()));
    //		clientInputPort.send(message);
    clientInputPort.send("hello from" + clientName);
  }
  @Override
  public void setGroupSendTrapper(GroupSendTrapper<Object, Object> newVal) {
    if (newVal.getDestination() == null) {
      newVal.setDestination(groupSendTrapper.getDestination());
      Tracer.warning("group send  trapper == mull!");
    } else if (newVal.getDestination()
        == groupSendTrapper) { // adding a new one in front of old one
      ConnectiontEventBus.newEvent(
          new AReplaceConnectionEvent(this, groupSendTrapper, newVal, true, false));

    } else {
      ConnectiontEventBus.newEvent(new AConnectionEvent(this, newVal, true));
    }

    this.groupSendTrapper = newVal;

    //		DistEventsBus.newEvent(new AConnectionEvent(this, newVal, true));
    //		groupSendTrapper.setDestination(sendTrapperDestination);
  }
Exemple #13
0
  //    public void updateOld(Listenable model, Object arg)
  //    {
  //    	try {
  //    		//System.out.println ("Listenable " + model + " arg " + arg);
  //		//System.out.println("update called");
  //    		RemoteShape shapeModel = null;
  //    		if (arg != null && arg instanceof Boolean && (Boolean) arg)
  //    			slModel.sort();
  //    		else if ((arg != null) && (arg instanceof SLPutCommand)) {
  //
  //		    //System.out.println("Update called on view " + this);
  //           //RemoteShape shapeModel = ((SLPutCommand) arg).getShapeModel();
  //           shapeModel = ((SLPutCommand) arg).getShapeModel();
  //           // System.out.println("Shape model:" + shapeModel);
  //            //shapeModel.addObserver(this);
  //            shapeModel.addListener(this);
  //			if (shapeModel instanceof ComponentModel) {
  //				ComponentModel componentModel = (ComponentModel) shapeModel;
  //			    Rectangle b = componentModel.getBounds();
  //				Component component = componentModel.getComponent();
  //				//System.out.println("comp model" + componentModel + "comp" + component);
  //				//System.out.println ("model bounds" + b + "comp bounds" + component.getBounds());
  //				component.setBounds(b.x, b.y, b.width, b.height);
  //			}
  //        }
  //    		// null means delete
  //		if (model instanceof SLModel &&  ((shapeModel == null ) || shapeModel instanceof
  // ComponentModel))
  //		     updateComponents(shapeModel);
  //		//System.out.println("calling repaint");
  //        container.repaint();
  //    	} catch (Exception e) {
  //    		System.out.println(e);
  //    		e.printStackTrace();
  //    	}
  //    }
  public void update(Listenable model, Object arg) {
    try {
      // System.out.println ("Listenable " + model + " arg " + arg);
      // System.out.println("update called");
      RemoteShape shapeModel = null;
      if (arg != null && arg instanceof Boolean && (Boolean) arg) slModel.sort();
      else if ((arg != null) && (arg instanceof SLPutCommand)) {

        // System.out.println("Update called on view " + this);
        // RemoteShape shapeModel = ((SLPutCommand)
        // arg).getShapeModel();
        shapeModel = ((SLPutCommand) arg).getShapeModel();
        // System.out.println("Shape model:" + shapeModel);
        // shapeModel.addObserver(this);
        shapeModel.addListener(this);
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          Rectangle b = componentModel.getBounds();
          Component component = componentModel.getComponent();
          // System.out.println("comp model" + componentModel + "comp"
          // + component);
          // System.out.println ("model bounds" + b + "comp bounds" +
          // component.getBounds());
          component.setBounds(b.x, b.y, b.width, b.height);
          List sortedComponents = slModel.getSortedComponentList();
          int insertPos = sortedComponents.indexOf(shapeModel);
          if (insertPos >= 0 && insertPos <= container.getComponentCount())
            container.add(component, insertPos);
          else {
            Tracer.error(
                "Illegal position:"
                    + insertPos
                    + " Same object:"
                    + shapeModel
                    + " at coordinates("
                    + shapeModel.getX()
                    + ", "
                    + shapeModel.getY()
                    + ") probably displayed twice in graphics window and its stacking order will be ignored");
            container.add(component);
          }
          component.addMouseListener(shapeEventNotifier);
        }
      } else if ((arg instanceof SLRemoveCommand)) {
        shapeModel = ((SLRemoveCommand) arg).getOriginalShapeModel();
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          container.remove(componentModel.getComponent());
        }
      }
      // null means delete
      //			if (model instanceof SLModel
      //					&& shapeModel instanceof ComponentModel)
      //				updateComponents(shapeModel);
      // System.out.println("calling repaint");
      if (!slModel.locked()) container.repaint();
    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }