1 23 package fr.dyade.aaa.jndi2.server; 24 25 import java.util.*; 26 import java.io.*; 27 28 import fr.dyade.aaa.agent.*; 29 30 import org.objectweb.util.monolog.api.BasicLevel; 31 import org.objectweb.util.monolog.api.Logger; 32 33 public class Container 34 extends Agent 35 implements BagSerializer { 36 37 private Vector entryPoints; 38 39 private LifeCycleListener lifeCycleListener; 40 41 private BagSerializer bagSerializer; 42 43 47 public Container() { 48 super("", true, AgentId.LocalJndiServiceStamp); 49 entryPoints = new Vector(2); 50 } 51 52 public void addEntryPoint(EntryPoint entryPoint) { 53 entryPoints.addElement(entryPoint); 54 } 55 56 public void setLifeCycleListener(LifeCycleListener lifeCycleListener) { 57 this.lifeCycleListener = lifeCycleListener; 58 } 59 60 public void setBagSerializer(BagSerializer bagSerializer) { 61 this.bagSerializer = bagSerializer; 62 } 63 64 public void react(AgentId from, Notification not) throws Exception { 65 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 66 Trace.logger.log(BasicLevel.DEBUG, "\n\nJndiServer[" + getId() + 67 "].react(" + from + ',' + not + ')'); 68 setNoSave(); 69 for (int i = 0; i < entryPoints.size(); i++) { 70 EntryPoint entryPoint = 71 (EntryPoint)entryPoints.elementAt(i); 72 if (entryPoint.accept(from, not)) { 73 return; 74 } 75 } 76 super.react(from, not); 77 } 78 79 public void agentInitialize(boolean firstTime) throws Exception { 80 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 81 Trace.logger.log(BasicLevel.DEBUG, "\n\nJndiServer[" + getId() + 82 "].agentInitialize(" + firstTime + ')'); 83 lifeCycleListener.agentInitialize(firstTime); 84 } 85 86 public void agentFinalize(boolean lastTime) { 87 lifeCycleListener.agentFinalize(lastTime); 88 } 89 90 void sendNotification(AgentId to, Notification not) { 91 sendTo(to, not); 92 } 93 94 public void writeBag(ObjectOutputStream out) 95 throws IOException { 96 if (bagSerializer != null) 97 bagSerializer.writeBag(out); 98 } 99 100 public void readBag(ObjectInputStream in) 101 throws IOException, ClassNotFoundException { 102 if (bagSerializer != null) 103 bagSerializer.readBag(in); 104 } 105 } 106 | Popular Tags |