KickJava   Java API By Example, From Geeks To Geeks.

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


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 fr.dyade.aaa.agent.*;
26 import fr.dyade.aaa.jndi2.msg.*;
27
28 import org.objectweb.util.monolog.api.BasicLevel;
29 import org.objectweb.util.monolog.api.Logger;
30
31 public class AgentEntryPoint implements EntryPoint {
32
33   private RequestManager manager;
34
35   public void setRequestManager(RequestManager manager) {
36     this.manager = manager;
37   }
38
39   public boolean accept(AgentId from, Notification not) throws Exception JavaDoc {
40     if (not instanceof JndiScriptRequestNot) {
41       doReact(from, (JndiScriptRequestNot)not);
42     } else return false;
43     return true;
44   }
45
46   /**
47    * Reacts to a JNDI script request. This is the notification
48    * entry point.
49    *
50    * @param not the JNDI script
51    */

52   private void doReact(AgentId from, JndiScriptRequestNot not) throws Exception JavaDoc {
53     if (Trace.logger.isLoggable(BasicLevel.DEBUG))
54       Trace.logger.log(BasicLevel.DEBUG,
55                        "AgentEntryPoint[" + manager.getId() +
56                        "].doReact(" + from +
57                        ",(JndiScriptRequestNot)" + not + ')');
58     JndiRequest[] requests = not.getRequests();
59     JndiReply[] replies = new JndiReply[requests.length];
60     for (int i = 0; i < requests.length; i++) {
61       AgentRequestContext reqCtx = new AgentRequestContext(
62         requests[i], from, not.reply());
63       replies[i] = manager.invoke(reqCtx);
64     }
65     if (not.reply()) {
66       // Reply to all the operations from the input
67
// script except those that are asynchronous.
68
// This can't happen in a centralized server.
69
// But in a distributed JNDI configuration, this
70
// server may be waiting for a notification reply
71
// from an other naming server.
72
// These asynchronous operations
73
// are acknowledged in separate notifications.
74
manager.sendTo(from, new JndiScriptReplyNot(replies));
75     }
76   }
77 }
78
Popular Tags