View Javadoc

1   package org.apache.jcs.utils.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  
25  /**
26   * The message sent by the discovery mechanism.
27   */
28  public class UDPDiscoveryMessage
29      implements Serializable
30  {
31      /** Don't change */
32      private static final long serialVersionUID = -5332377899560951793L;
33  
34      /**
35       * This is the periodic broadcast of a servers location. This type of message is also sent in
36       * response to a REQUEST_BROADCAST.
37       */
38      public static final int PASSIVE_BROADCAST = 0;
39  
40      /**
41       * This asks recipients to broadcast their location. This is used on startup.
42       */
43      public static final int REQUEST_BROADCAST = 1;
44  
45      /**
46       * This message instructs the receiver to remove this service from its list.
47       */
48      public static final int REMOVE_BROADCAST = 2;
49  
50      /** The message type */
51      private int messageType = PASSIVE_BROADCAST;
52  
53      /** udp port */
54      private int port = 6789;
55  
56      /** UDP host */
57      private String host = "228.5.6.7";
58  
59      /** Id of the requestor, allows self-filtration */
60      private long requesterId;
61  
62      /** Names of regions */
63      private ArrayList<String> cacheNames = new ArrayList<String>();
64  
65      /**
66       * @param port The port to set.
67       */
68      public void setPort( int port )
69      {
70          this.port = port;
71      }
72  
73      /**
74       * @return Returns the port.
75       */
76      public int getPort()
77      {
78          return port;
79      }
80  
81      /**
82       * @param host The host to set.
83       */
84      public void setHost( String host )
85      {
86          this.host = host;
87      }
88  
89      /**
90       * @return Returns the host.
91       */
92      public String getHost()
93      {
94          return host;
95      }
96  
97      /**
98       * @param requesterId The requesterId to set.
99       */
100     public void setRequesterId( long requesterId )
101     {
102         this.requesterId = requesterId;
103     }
104 
105     /**
106      * @return Returns the requesterId.
107      */
108     public long getRequesterId()
109     {
110         return requesterId;
111     }
112 
113     /**
114      * @param messageType The messageType to set.
115      */
116     public void setMessageType( int messageType )
117     {
118         this.messageType = messageType;
119     }
120 
121     /**
122      * @return Returns the messageType.
123      */
124     public int getMessageType()
125     {
126         return messageType;
127     }
128 
129     /**
130      * @param cacheNames The cacheNames to set.
131      */
132     public void setCacheNames( ArrayList<String> cacheNames )
133     {
134         this.cacheNames = cacheNames;
135     }
136 
137     /**
138      * @return Returns the cacheNames.
139      */
140     public ArrayList<String> getCacheNames()
141     {
142         return cacheNames;
143     }
144 
145     /**
146      * @return debugging string
147      */
148     @Override
149     public String toString()
150     {
151         StringBuffer buf = new StringBuffer();
152         buf.append( "\n host = [" + host + "]" );
153         buf.append( "\n port = [" + port + "]" );
154         buf.append( "\n requesterId = [" + requesterId + "]" );
155         buf.append( "\n messageType = [" + messageType + "]" );
156         buf.append( "\n Cache Names" );
157         for (String name : cacheNames)
158         {
159             buf.append( " cacheName = [" + name + "]" );
160         }
161         return buf.toString();
162     }
163 }