View Javadoc

1   /*
2    * Copyright (c) 1998-2002 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   
19  package jgroup.arm;
20  
21  import java.io.IOException;
22  import java.io.ObjectInput;
23  import java.io.ObjectOutput;
24  import java.net.InetAddress;
25  import java.rmi.RemoteException;
26  
27  import jgroup.core.arm.ARMEvent;
28  import jgroup.core.arm.DistributionScheme;
29  import jgroup.relacs.config.DistributedSystemConfig;
30  import jgroup.relacs.config.Host;
31  import jgroup.util.Network;
32  
33  import org.apache.log4j.Logger;
34  
35  /**
36   *  Event to notify the replication manager of the availability of an
37   *  execution daemon running on the initiating host.
38   *
39   *  @author Hein Meling
40   *  @since Jgroup 1.2
41   */
42  final class EDPresentEvent
43    implements ARMEvent
44  {
45  
46    private static final long serialVersionUID = 5047243468822963123L;
47  
48  
49    ////////////////////////////////////////////////////////////////////////////////////////////
50    // Logger
51    ////////////////////////////////////////////////////////////////////////////////////////////
52  
53    /** Obtain logger for this class */
54    private static final Logger log = Logger.getLogger(EDPresentEvent.class);
55  
56  
57    ////////////////////////////////////////////////////////////////////////////////////////////
58    // Private Fields
59    ////////////////////////////////////////////////////////////////////////////////////////////
60  
61    /**
62     *  An integer based <code>InetAddress</code> for the machine running
63     *  the execution daemon that generated this event.
64     */
65    private int intAdr;
66  
67  
68    ////////////////////////////////////////////////////////////////////////////////////////////
69    // Constructors
70    ////////////////////////////////////////////////////////////////////////////////////////////
71  
72    /**
73     *  Default constructor for externalization.
74     */
75    public EDPresentEvent() { }
76  
77  
78    /**
79     *  Construct a new <code>EDPresentEvent</code> instance.
80     */
81    EDPresentEvent(InetAddress inet)
82    {
83      intAdr = Network.translate(inet);
84    }
85  
86  
87    ////////////////////////////////////////////////////////////////////////////////////////////
88    // ARMEvent interface methods
89    ////////////////////////////////////////////////////////////////////////////////////////////
90  
91    /**
92     *  The event handling is performed by the event object itself, at the
93     *  (replication manager) receiver side. <p>
94     *
95     *  The handler method is invoked by the replication manager, allowing
96     *  an execution daemon to notify its presence to the replication
97     *  manager.  The host location for the execution daemon is provided
98     *  through the constructor. <p>
99     * 
100    *  We update the internal tables of the host object associated with
101    *  the internet address attached with this object.  We assume that
102    *  the notifying host is specified in the configuration, otherwise
103    *  nothing happens.
104    *
105    *  @exception RemoteException
106    *    Raised if the remote operation failed.
107    *  @exception java.net.UnknownHostException
108    *    Raised if the invoking host could not be found through DNS.
109    */
110   public void handle(DistributionScheme distScheme)
111     throws Exception
112   {
113     InetAddress inet = Network.translate(intAdr);
114     if (log.isDebugEnabled())
115       log.debug("Received new host: " + inet);
116     Host host = DistributedSystemConfig.getHost(inet);
117     if (host != null) {
118       // update the host internal tables
119       host.suspect();
120     }
121   }
122 
123 
124   /* (non-Javadoc)
125    * @see jgroup.core.arm.ARMEvent#getGroupId()
126    */
127   public int getGroupId()
128   {
129     return -1;
130   }
131 
132 
133   /* (non-Javadoc)
134    * @see jgroup.core.arm.ARMEvent#getObject()
135    */
136   public Object getObject()
137   {
138     return null;
139   }
140 
141 
142   ////////////////////////////////////////////////////////////////////////////////////////////
143   // Methods from the Externalizable interface (as required by the ARMEvent interface)
144   ////////////////////////////////////////////////////////////////////////////////////////////
145 
146   /**
147    *  Restores the content of this object from the marshalled data
148    *  contained in the specified input stream.
149    *
150    *  @param in
151    *    The stream to be read from.
152    *  @exception IOException
153    *    Thrown if there was problems unmarshalling the input stream.
154    *  @exception ClassNotFoundException
155    *    Thrown if the local classloader cannot find a class marshalled
156    *    in the stream.
157    */
158   public void readExternal(ObjectInput in)
159     throws IOException, ClassNotFoundException
160   {
161     intAdr = in.readInt();
162   }
163 
164 
165   /**
166    *  Marshals the content of this object to the specified output
167    *  stream.
168    * 
169    *  @param out
170    *    The stream to write this object into.
171    *  @exception IOException
172    *    Thrown if there was problems unmarshalling the input stream.
173    */
174   public void writeExternal(ObjectOutput out)
175     throws IOException
176   {
177     out.writeInt(intAdr);
178   }
179 
180 } // END EDPresentEvent