001package org.apache.commons.jcs.utils.discovery;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.Serializable;
023import java.util.ArrayList;
024
025/**
026 * The message sent by the discovery mechanism.
027 */
028public class UDPDiscoveryMessage
029    implements Serializable
030{
031    /** Don't change */
032    private static final long serialVersionUID = -5332377899560951793L;
033
034    public enum BroadcastType
035    {
036        /**
037         * This is the periodic broadcast of a servers location. This type of message is also sent in
038         * response to a REQUEST_BROADCAST.
039         */
040        PASSIVE,
041
042        /**
043         * This asks recipients to broadcast their location. This is used on startup.
044         */
045        REQUEST,
046
047        /**
048         * This message instructs the receiver to remove this service from its list.
049         */
050        REMOVE
051    }
052
053    /** The message type */
054    private BroadcastType messageType = BroadcastType.PASSIVE;
055
056    /** udp port */
057    private int port = 6789;
058
059    /** UDP host */
060    private String host = "228.5.6.7";
061
062    /** Id of the requester, allows self-filtration */
063    private long requesterId;
064
065    /** Names of regions */
066    private ArrayList<String> cacheNames = new ArrayList<String>();
067
068    /**
069     * @param port The port to set.
070     */
071    public void setPort( int port )
072    {
073        this.port = port;
074    }
075
076    /**
077     * @return Returns the port.
078     */
079    public int getPort()
080    {
081        return port;
082    }
083
084    /**
085     * @param host The host to set.
086     */
087    public void setHost( String host )
088    {
089        this.host = host;
090    }
091
092    /**
093     * @return Returns the host.
094     */
095    public String getHost()
096    {
097        return host;
098    }
099
100    /**
101     * @param requesterId The requesterId to set.
102     */
103    public void setRequesterId( 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( 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( 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        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 (String name : cacheNames)
161        {
162            buf.append( " cacheName = [" + name + "]" );
163        }
164        return buf.toString();
165    }
166}