public void deliverToApplication(RouteMessage msg) { PastryAppl appl = dispatch.getDestinationByAddress(msg.getAuxAddress()); if (appl == null) { if (msg.sendFailed(new AppNotRegisteredException(msg.getAuxAddress()))) { if (logger.level <= Logger.CONFIG) logger.log( "Dropping message " + msg + " because the application address " + msg.getAuxAddress() + " is unknown."); } else { if (logger.level <= Logger.WARNING) logger.log( "Dropping message " + msg + " because the application address " + msg.getAuxAddress() + " is unknown."); } return; } appl.receiveMessage(msg); // thePastryNode.receiveMessage(msg); }
/** * Dispatches a message to the appropriate receiver. * * <p>It will buffer the message under the following conditions: 1) The MessageReceiver is not yet * registered. 2) The MessageReceiver is a PastryAppl, and localNode.isReady() == false * * @param msg the message. * @return true if message could be dispatched, false otherwise. */ public boolean dispatchMessage(Message msg) { if (msg.getDestination() == 0) { Logger logger = localNode.getEnvironment().getLogManager().getLogger(MessageDispatch.class, null); if (logger.level <= Logger.WARNING) logger.logException( "Message " + msg + "," + msg.getClass().getName() + " has no destination.", new Exception("Stack Trace")); return false; } // NOTE: There is no safety issue with calling localNode.isReady() because this is on the // PastryThread, and the only way to set a node ready is also on the ready thread. PastryAppl mr = (PastryAppl) addressBook.get(Integer.valueOf(msg.getDestination())); if (mr == null) { if ((logger.level <= Logger.FINE) || (localNode.isReady() && (logger.level <= Logger.INFO))) { logger.log( "Dropping message " + msg + " because the application address " + msg.getDestination() + " is unknown."); } return false; } else { mr.receiveMessage(msg); return true; } }
public void destroy() { Iterator<PastryAppl> i = addressBook.values().iterator(); while (i.hasNext()) { PastryAppl mr = i.next(); if (logger.level <= Logger.INFO) logger.log("Destroying " + mr); mr.destroy(); } addressBook.clear(); }
/** * Registers a receiver with the mail service. * * @param name a name for a receiver. * @param receiver the receiver. */ public void registerReceiver(int address, PastryAppl receiver) { // the stack trace is to figure out who registered for what, it is not an error if (logger.level <= Logger.FINE) logger.log("Registering " + receiver + " for address " + address); if (logger.level <= Logger.FINEST) logger.logException( "Registering receiver for address " + address, new Exception("stack trace")); if (addressBook.get(Integer.valueOf(address)) != null) { throw new IllegalArgumentException( "Registering receiver for already-registered address " + address); // if (logger.level <= Logger.SEVERE) logger.logException( // "ERROR - Registering receiver for already-registered address " + address, new // Exception("stack trace")); } deserializer.setDeserializer(address, receiver.getDeserializer()); addressBook.put(Integer.valueOf(address), receiver); }