KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > indexing > WBManager


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Uri Schneider.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.indexing;
48
49 import java.net.SocketAddress JavaDoc;
50 import java.util.Set JavaDoc;
51
52 import org.apache.commons.logging.Log;
53 import org.apache.commons.logging.LogFactory;
54 import org.mr.MantaAgent;
55 import org.mr.core.configuration.ConfigManager;
56 import org.mr.core.net.MWBTransportImpl;
57 import org.mr.core.net.NetworkManager;
58 import org.mr.core.net.TransportImpl;
59 import org.mr.kernel.world.WorldModeler;
60
61 /**
62  * WBManager.java
63  *
64  * This is a manager object for the WBLink feature.
65  *
66  * Created: Thu Jan 06 17:13:23 2005
67  *
68  * @author Uri Schneider
69  * @version 1.0
70  */

71 public class WBManager {
72     private String JavaDoc mwbPassword;
73     private TransportImpl mwbImpl;
74     private WBHandler wbHandler;
75     private Log log;
76
77     public WBManager() {
78         this.log = LogFactory.getLog("WBLink");
79         if (this.log.isInfoEnabled()) {
80             this.log.info("WBLink starting");
81         }
82
83         MantaAgent agent = MantaAgent.getInstance();
84         ConfigManager config =
85             agent.getSingletonRepository().getConfigManager();
86
87         if (!config.getBooleanProperty("wblink.enabled", false)) {
88             if (this.log.isInfoEnabled()) {
89                 this.log.info("WBLink is disabled");
90             }
91             return;
92         }
93         if (this.log.isInfoEnabled()) {
94             this.log.info("WBLink starting");
95         }
96
97         this.mwbPassword = config.getStringProperty("wblink.password");
98         int mwbLeaseSecs = config.getIntProperty("wblink.lease", 20);
99
100 // if (irsHost == null || irsPort == -1) {
101
// if (this.log.isInfoEnabled()) {
102
// this.log.info("No address for IRS found in the " +
103
// "configuration. Role advertisement and " +
104
// "message routing using the IRS WILL NOT BE " +
105
// "AVAILABLE.");
106
// }
107
// return;
108
// }
109
// irsAddress = new InetSocketAddress(irsHost, irsPort);
110

111         // create a transport for the WB
112
WorldModeler world = agent.getSingletonRepository().getWorldModeler();
113         String JavaDoc domainName = world.getDefaultDomainName();
114         Set JavaDoc irsTransports = world.getAgentTransportInfo(domainName, "mwb");
115         if (irsTransports == null || irsTransports.isEmpty()) {
116             if (this.log.isWarnEnabled()) {
117                 this.log.warn("No transport information for the MantaRay WB " +
118                               "found in the world map. In order to " +
119                               "communicate with the MWB a peer with the " +
120                               "name 'mwb' and with a transport type of " +
121                               "'MWB' must be present in the world map. " +
122                               "Role advertisement and message routing using " +
123                               "the WB WILL NOT BE AVAILABLE.");
124             }
125             return;
126         }
127         if (this.mwbPassword == null) {
128             if (this.log.isWarnEnabled()) {
129                 this.log.warn("No password to use with the WB found in the " +
130                               "configuration. Role advertisement and " +
131                               "message routing using the WB WILL NOT BE " +
132                               "AVAILABLE.");
133             }
134             return;
135         }
136
137         // add the WB advertiser to the ServiceActorControlCenter
138
WBAdvertiser advertiser = new WBAdvertiser(mwbLeaseSecs);
139         agent.getSingletonRepository().getServiceActorControlCenter().setWBSender(advertiser);
140         NetworkManager network =
141             MantaAgent.getInstance().getSingletonRepository().getNetworkManager();
142         network.addAgentStateListener("mwb", advertiser);
143
144         if (config.getBooleanProperty("wblink.exclusive", false)) {
145             agent.getSingletonRepository().getServiceActorControlCenter().setDefaultSender(null);
146         }
147
148         // init IRSHandler for incoming messages
149
this.wbHandler = new WBHandler();
150     } // IRSManager constructor
151

152     public synchronized TransportImpl getIRSTransportImpl(SocketAddress JavaDoc local,
153                                                           SocketAddress JavaDoc remote)
154     {
155         try {
156             if ((mwbImpl == null || mwbImpl.isDown()) && mwbPassword != null) {
157                 mwbImpl = new MWBTransportImpl(local, remote, mwbPassword);
158             }
159         } catch (Exception JavaDoc e) {
160             System.err.println("MWBTransportImpl init returned an error");
161             e.printStackTrace();
162         }
163
164         return mwbImpl;
165     }
166
167     public WBHandler getWbHandler() {
168         return this.wbHandler;
169     }
170 } // IRSManager
171
Popular Tags