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