1 /* 2 * Copyright (c) 1998-2005 The Jgroup Team. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License version 2 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * 17 */ 18 package jgroup.relacs.gm; 19 20 import java.io.IOException; 21 import java.lang.reflect.Proxy; 22 23 import jgroup.core.GroupManager; 24 import jgroup.jini.LookupManager; 25 import jgroup.relacs.gmi.GroupInvocationHandler; 26 27 import org.apache.log4j.Logger; 28 29 /** 30 * Layer implementing the <code>GregLookupService</code> interface. 31 * 32 * @author Rohnny Moland 33 * @since Jgroup 2.2 34 */ 35 public final class GregLookupLayer 36 implements GregLookupService 37 { 38 39 // ////////////////////////////////////////////////////////////////////////////////////////// 40 // Logger 41 // ////////////////////////////////////////////////////////////////////////////////////////// 42 43 /** Obtain logger for this class */ 44 private static final Logger log = Logger.getLogger(GregLookupLayer.class); 45 46 // ////////////////////////////////////////////////////////////////////////////////////////// 47 // Fields 48 // ////////////////////////////////////////////////////////////////////////////////////////// 49 50 /** The group manager reference associated with this layer */ 51 private GroupManager gm; 52 53 // ////////////////////////////////////////////////////////////////////////////////////////// 54 // Constructor 55 // ////////////////////////////////////////////////////////////////////////////////////////// 56 57 /** 58 * Construct the <code>LookupLayer</code>. 59 * 60 * @param gm 61 * The group manager object to which this layer is associated 62 */ 63 private GregLookupLayer(GroupManager gm) 64 { 65 this.gm = gm; 66 } 67 68 // ////////////////////////////////////////////////////////////////////////////////////////// 69 // Static factory 70 // ////////////////////////////////////////////////////////////////////////////////////////// 71 72 public static GregLookupLayer getLayer(GroupManager gm) 73 { 74 return new GregLookupLayer(gm); 75 } 76 77 // ////////////////////////////////////////////////////////////////////////////////////////// 78 // Layer interface methods 79 // ////////////////////////////////////////////////////////////////////////////////////////// 80 81 public void addListener(Object listener) 82 { 83 // should never be called, since Lookup does not provide a listener 84 // interface 85 } 86 87 // ////////////////////////////////////////////////////////////////////////////////////////// 88 // GregLookupService interface methods 89 // ////////////////////////////////////////////////////////////////////////////////////////// 90 91 92 /* 93 * (non-Javadoc) 94 * 95 * @see jgroup.core.registry.LookupService#lookup(java.lang.String, 96 * java.lang.Class) 97 */ 98 public Object lookup(String name) throws IOException 99 { 100 Object server = LookupManager.lookup(name); 101 GroupInvocationHandler handler = (GroupInvocationHandler) Proxy.getInvocationHandler(server); 102 handler.setGroupManager(gm); 103 return server; 104 } 105 106 } // END of GregLookupLayer