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.lang.reflect.Proxy;
25  import java.rmi.Remote;
26  import java.rmi.RemoteException;
27  import java.util.Iterator;
28  
29  import jgroup.core.MemberId;
30  import jgroup.core.registry.DependableRegistry.RegistryEntry;
31  import net.jini.export.Exporter;
32  import net.jini.jeri.BasicILFactory;
33  import net.jini.jeri.BasicJeriExporter;
34  import net.jini.jeri.ObjectEndpoint;
35  import net.jini.jeri.InvocationLayerFactory.Instances;
36  import net.jini.jeri.tcp.TcpServerEndpoint;
37  
38  /**
39   * The registry entry type required to use the BasicJeriExport
40   * in binding with the dependable registry.
41   *
42   * @author Hein Meling
43   */
44  public class BasicJeriRegistryEntry
45    implements RegistryEntry
46  {
47  
48    ////////////////////////////////////////////////////////////////////////////////////////////
49    // Constants
50    ////////////////////////////////////////////////////////////////////////////////////////////
51  
52    private static final long serialVersionUID = 4490998440934560367L;
53  
54    public final static String TYPE = "BasicJeri";
55  
56  
57    ////////////////////////////////////////////////////////////////////////////////////////////
58    // Constructors
59    ////////////////////////////////////////////////////////////////////////////////////////////
60  
61    /** Endpoint */
62    private MemberId me;
63  
64    /** Service name */
65    private String service;
66  
67    /** The invocation layer factory */
68    private BasicILFactory ilfactory;
69  
70  
71    private ObjectEndpoint oe;
72  
73  
74    private Remote impl;
75  
76  
77    private TcpServerEndpoint se;
78  
79  
80    ////////////////////////////////////////////////////////////////////////////////////////////
81    // Constructors
82    ////////////////////////////////////////////////////////////////////////////////////////////
83  
84    /** Create empty entry, for externalization */
85    public BasicJeriRegistryEntry() {}
86  
87    
88    /**
89     * Create a new <code>BasicJeriRegistryEntry</code>.
90     */
91    BasicJeriRegistryEntry(Remote impl, ObjectEndpoint oe)
92    {
93      this.se = TcpServerEndpoint.getInstance(0);
94      this.ilfactory = new BasicILFactory();
95      Exporter exporter = new BasicJeriExporter(se, ilfactory);
96      this.impl = impl;
97      this.oe = oe;
98    }
99  
100 
101   ////////////////////////////////////////////////////////////////////////////////////////////
102   // Methods from DependableRegistry.RegistryEntry
103   ////////////////////////////////////////////////////////////////////////////////////////////
104 
105   /* (non-Javadoc)
106    * @see jgroup.core.registry.DependableRegistry.RegistryEntry#getType()
107    */
108   public String getType()
109   {
110     return TYPE;
111   }
112 
113 
114   /* (non-Javadoc)
115    * @see jgroup.core.registry.DependableRegistry.RegistryEntry#createInvocationHandler(java.lang.String, java.util.Iterator)
116    */
117   public InvocationHandler createInvocationHandler(String serviceName, Iterator entries)
118     throws RemoteException
119   {
120     Instances inst = ilfactory.createInstances(impl, oe, se);
121     return Proxy.getInvocationHandler(inst.getProxy());
122   }
123 
124 
125   ////////////////////////////////////////////////////////////////////////////////////////////
126   // Methods from Externalizable inherited through DependableRegistry.RegistryEntry
127   ////////////////////////////////////////////////////////////////////////////////////////////
128 
129   /* (non-javadoc)
130    * @see java.io.Externalizable#readExternal(ObjectInput)
131    */
132   public void readExternal(ObjectInput in)
133     throws IOException, ClassNotFoundException
134   {
135     service = (String) in.readObject();
136     me = (MemberId) in.readObject();
137   }
138 
139   /* (non-javadoc)
140    * @see java.io.Externalizable#writeExternal(ObjectOutput)
141    */
142   public void writeExternal(ObjectOutput out)
143     throws IOException
144   {
145     out.writeObject(service);
146     out.writeObject(me);
147   }
148 
149 } // END JeriRegistryEntry