KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > server > Container


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2003 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): David Feliot
22  */

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   /**
44    * This agent cannot be swapped and has
45    * a reserved identifier on each agent server.
46    */

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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
102     if (bagSerializer != null)
103       bagSerializer.readBag(in);
104   }
105 }
106
Popular Tags