KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > discovery > DiscGreeting


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  * --------------------------------------------------------------------------
20  * $Id: DiscGreeting.java,v 1.2 2005/05/22 03:38:51 vivekl Exp $
21  * --------------------------------------------------------------------------
22  */

23
24 package org.objectweb.jonas.discovery;
25
26 /**
27  * This class represents a special greeting message which has two uses:
28  * 1) To act as a broadcast to the domain that a new server with a given
29  * server name has started. It also includes a port that the server will
30  * listen to objections at, the domain name and state set to STARTUP.
31  * 2) To inform the newly started server that server name is already in use
32  * by another server.
33  *
34  * @author Vivek Lakshmanan
35  * @version 1.0
36  */

37 public class DiscGreeting extends DiscMessage {
38     /**
39      *
40      */

41     public static final String JavaDoc STARTUP = "starting up";
42     /**
43      *
44      */

45     public static final String JavaDoc DUPLICATE_NAME = "duplicate server name found";
46     /**
47      *
48      */

49     private String JavaDoc state = null;
50     /**
51      *
52      */

53     private String JavaDoc serverName = null;
54     /**
55      *
56      */

57     private String JavaDoc domainName = null;
58
59     private String JavaDoc serverId = null;
60
61     /**
62      * @param sourceAddress
63      * @param sourcePort
64      */

65     public DiscGreeting(String JavaDoc sourceAddress, int sourcePort) {
66         super(sourceAddress, sourcePort);
67     }
68
69     /**
70      * Constructor for a Discovery Greeting.
71      * @param sourceAddress
72      * the host address to use to receive a response.
73      * @param sourcePort
74      * is the port used in the case of a point to point response.
75      * @param serverName
76      * is Jonas server name.
77      * @param domainName
78      * is Jonas domain name.
79      * @param startingUp
80      * is this server starting up or is it reporting back with a
81      * notification stating that it owns this server name?
82      * @param serverId TODO
83      */

84     public DiscGreeting(String JavaDoc sourceAddress, int sourcePort,
85             String JavaDoc serverName, String JavaDoc domainName, boolean startingUp,
86             String JavaDoc serverId) {
87         super(sourceAddress, sourcePort);
88         this.serverName = serverName;
89         this.domainName = domainName;
90         this.serverId = serverId;
91
92         if (startingUp) {
93             this.state = STARTUP;
94         } else {
95             this.state = DUPLICATE_NAME;
96         }
97
98     }
99
100     /**
101      * returns server name.
102      *
103      * @return serverName
104      */

105     public String JavaDoc getServerName() {
106         return serverName;
107     }
108
109     /**
110      * returns domain name.
111      *
112      * @return domain name.
113      */

114     public String JavaDoc getDomainName() {
115         return domainName;
116     }
117
118     /**
119      * sets the domain name.
120      *
121      * @param domainName the management domain name
122      */

123     public void setDomainName(String JavaDoc domainName) {
124         this.domainName = domainName;
125     }
126
127     /**
128      * sets the serverName
129      *
130      * @param serverName the name of the server sending the discovery greeting
131      */

132     public void setServerName(String JavaDoc serverName) {
133         this.serverName = serverName;
134     }
135
136     /**
137      * @return server state.
138      */

139     public String JavaDoc getState() {
140         return state;
141     }
142
143     /**
144      * sets the server state : STARTINGUP or DUPLICATE_NAME.
145      *
146      * @param state state of the server sending the discovery greeting, one of DiscGreeting.STARTUP or DiscGreeting.DUPLICATE_NAME
147      */

148     public void setState(String JavaDoc state) {
149         this.state = state;
150     }
151
152     /**
153      * The string version of the message
154      * @return the message
155      */

156     public String JavaDoc toString() {
157         String JavaDoc str = super.getSourceAddress() + ": " + super.getSourcePort() + " State="
158         + state + " DomainName=" + domainName + " ServerName= " + serverName + " serverId= " + serverId;
159         return str;
160
161     }
162
163     public String JavaDoc getServerId() {
164         return serverId;
165     }
166
167     public void setServerId(String JavaDoc serverId) {
168         this.serverId = serverId;
169     }
170
171
172 }
173
Popular Tags