View Javadoc

1   package org.apache.jcs.auxiliary.lateral.socket.tcp.discovery;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Serializable;
23  import java.util.ArrayList;
24  import java.util.Iterator;
25  
26  /***
27   *
28   * @author Aaron Smuts
29   *
30   */
31  public class UDPDiscoveryMessage
32      implements Serializable
33  {
34  
35      private static final long serialVersionUID = -5332377899560951794L;
36  
37      /***
38       * This is the periodic broadcast of a servers location. This type of
39       * message is also sent in response to a REQUEST_BROADCAST.
40       */
41      public static final int PASSIVE_BROADCAST = 0;
42  
43      /***
44       * This asks recipients to broadcast their location. This is used on
45       * startup.
46       */
47      public static final int REQUEST_BROADCAST = 1;
48  
49      private int messageType = PASSIVE_BROADCAST;
50  
51      private int port = 6789;
52  
53      private String host = "228.5.6.7";
54  
55      /*** Description of the Field */
56      private long requesterId;
57  
58      private ArrayList cacheNames = new ArrayList();
59  
60      /***
61       * @param port
62       *            The port to set.
63       */
64      public void setPort( int port )
65      {
66          this.port = port;
67      }
68  
69      /***
70       * @return Returns the port.
71       */
72      public int getPort()
73      {
74          return port;
75      }
76  
77      /***
78       * @param host
79       *            The host to set.
80       */
81      public void setHost( String host )
82      {
83          this.host = host;
84      }
85  
86      /***
87       * @return Returns the host.
88       */
89      public String getHost()
90      {
91          return host;
92      }
93  
94      /***
95       * @param requesterId
96       *            The requesterId to set.
97       */
98      public void setRequesterId( long requesterId )
99      {
100         this.requesterId = requesterId;
101     }
102 
103     /***
104      * @return Returns the requesterId.
105      */
106     public long getRequesterId()
107     {
108         return requesterId;
109     }
110 
111     /***
112      * @param messageType
113      *            The messageType to set.
114      */
115     public void setMessageType( int messageType )
116     {
117         this.messageType = messageType;
118     }
119 
120     /***
121      * @return Returns the messageType.
122      */
123     public int getMessageType()
124     {
125         return messageType;
126     }
127 
128     /***
129      * @param cacheNames
130      *            The cacheNames to set.
131      */
132     public void setCacheNames( ArrayList cacheNames )
133     {
134         this.cacheNames = cacheNames;
135     }
136 
137     /***
138      * @return Returns the cacheNames.
139      */
140     public ArrayList getCacheNames()
141     {
142         return cacheNames;
143     }
144 
145     /*
146      * (non-Javadoc)
147      *
148      * @see java.lang.Object#toString()
149      */
150     public String toString()
151     {
152         StringBuffer buf = new StringBuffer();
153         buf.append( "\n host = [" + host + "]" );
154         buf.append( "\n port = [" + port + "]" );
155         buf.append( "\n requesterId = [" + requesterId + "]" );
156         buf.append( "\n messageType = [" + messageType + "]" );
157 
158         buf.append( "\n Cache Names" );
159         Iterator it = cacheNames.iterator();
160         while ( it.hasNext() )
161         {
162             String name = (String) it.next();
163             buf.append( " cacheName = [" + name + "]" );
164         }
165         return buf.toString();
166     }
167 
168 }