View Javadoc

1   /*
2    * Copyright (c) 1998-2003 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.gmi;
19  
20  import java.io.IOException;
21  import java.io.ObjectInput;
22  import java.io.ObjectOutput;
23  import java.lang.reflect.InvocationHandler;
24  import java.rmi.RemoteException;
25  import java.util.Iterator;
26  
27  import jgroup.core.MemberId;
28  import jgroup.core.registry.DependableRegistry.RegistryEntry;
29  
30  /**
31   * The registry entry type required by the JeriEGMI layer.
32   *
33   * @author Tor Arve Stangeland
34   * @author Hein Meling
35   */
36  public class JeriRegistryEntry
37    implements RegistryEntry
38  {
39  
40    ////////////////////////////////////////////////////////////////////////////////////////////
41    // Constants
42    ////////////////////////////////////////////////////////////////////////////////////////////
43  
44    private static final long serialVersionUID = -1665657844632204570L;
45  
46  
47    public final static String TYPE = "JeriEGMI";
48  
49  
50    ////////////////////////////////////////////////////////////////////////////////////////////
51    // Constructors
52    ////////////////////////////////////////////////////////////////////////////////////////////
53  
54    /** The member containing the Endpoint */
55    private MemberId me;
56  
57    /** Service name */
58    private String service;
59  
60    /** The table of methods associated with the service */
61    private MethodTable methodTable;
62    
63  
64    ////////////////////////////////////////////////////////////////////////////////////////////
65    // Constructors
66    ////////////////////////////////////////////////////////////////////////////////////////////
67  
68    /** Create empty entry, for externalization */
69    public JeriRegistryEntry() {}
70  
71    
72    /**
73     * Create a new <code>JeriRegistryEntry</code> with the given service name
74     * and <code>Endpoint</code>.
75     * @param service Service name
76     * @param me <code>MemberId</code> containing the <code>Endpoint</code> to 
77     * communicate through
78     * @param methodTable the table of methods associated with the service
79     */
80    JeriRegistryEntry(String service, MemberId me, MethodTable methodTable)
81    {
82      this.service = service;
83      this.me = me;
84      this.methodTable = methodTable;
85    }
86  
87  
88    ////////////////////////////////////////////////////////////////////////////////////////////
89    // Access methods for JeriRegistryEntry
90    ////////////////////////////////////////////////////////////////////////////////////////////
91  
92    /**
93     * Returns the member.
94     */
95    public MemberId getMember()
96    {
97      return me;
98    }
99  
100   /**
101    * Returns the service.
102    */
103   public String getService()
104   {
105     return service;
106   }
107 
108 
109   ////////////////////////////////////////////////////////////////////////////////////////////
110   // Methods from DependableRegistry.RegistryEntry
111   ////////////////////////////////////////////////////////////////////////////////////////////
112 
113   /* (non-Javadoc)
114    * @see jgroup.core.registry.DependableRegistry.RegistryEntry#getType()
115    */
116   public String getType()
117   {
118     return TYPE;
119   }
120 
121 
122   /* (non-Javadoc)
123    * @see jgroup.core.registry.DependableRegistry.RegistryEntry#createInvocationHandler(java.lang.String, java.util.Iterator)
124    */
125   public InvocationHandler createInvocationHandler(String serviceName, Iterator entries)
126     throws RemoteException
127   {
128     GroupEndPoint gep = new GroupEndPoint(serviceName);
129     while (entries.hasNext()) {
130       JeriRegistryEntry entry = (JeriRegistryEntry) entries.next();
131       gep.addMember(entry.getMember());
132     }
133     GroupInvocationHandler handler = new GroupInvocationHandler(gep, methodTable);
134     return handler;
135   }
136 
137 
138   ////////////////////////////////////////////////////////////////////////////////////////////
139   // Methods from Externalizable inherited through DependableRegistry.RegistryEntry
140   ////////////////////////////////////////////////////////////////////////////////////////////
141 
142   /* (non-javadoc)
143    * @see java.io.Externalizable#readExternal(ObjectInput)
144    */
145   public void readExternal(ObjectInput in)
146     throws IOException, ClassNotFoundException
147   {
148     service = (String) in.readObject();
149     me = (MemberId) in.readObject();
150     methodTable = (MethodTable) in.readObject();
151   }
152 
153   /* (non-javadoc)
154    * @see java.io.Externalizable#writeExternal(ObjectOutput)
155    */
156   public void writeExternal(ObjectOutput out)
157     throws IOException
158   {
159     out.writeObject(service);
160     out.writeObject(me);
161     out.writeObject(methodTable);
162   }
163 
164 } // END JeriRegistryEntry