KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > indexing > messages > ServiceParticipationChanged


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Uri Schneider.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.indexing.messages;
48
49 import java.io.IOException JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Set JavaDoc;
53
54 import org.mr.core.util.byteable.Byteable;
55 import org.mr.core.util.byteable.ByteableInputStream;
56 import org.mr.core.util.byteable.ByteableList;
57 import org.mr.core.util.byteable.ByteableMap;
58 import org.mr.core.util.byteable.ByteableOutputStream;
59 import org.mr.core.util.byteable.ByteableRegistry;
60 import org.mr.kernel.services.ServiceActor;
61
62 /**
63  * ServiceParticipationChanged.java
64  *
65  *
66  * Created: Mon Dec 06 17:56:30 2004
67  *
68  * @author Uri Schneider
69  * @version 1.0
70  */

71 public class ServiceParticipationChanged implements Byteable {
72     private final static String JavaDoc typeString = "ServiceParticipationChanged";
73
74     public final static String JavaDoc CONSUMER = "consumer";
75     public final static String JavaDoc PRODUCER = "producer";
76     public final static String JavaDoc COORDINATOR = "coordinator";
77     public final static String JavaDoc TOPIC = "topic";
78     public final static String JavaDoc QUEUE = "queue";
79
80     private String JavaDoc domainName;
81     private String JavaDoc serviceName;
82     private String JavaDoc serviceType;
83 // private String serviceRole;
84
// private boolean add;
85
private byte operation;
86 // private ByteableList agents;
87
private ByteableMap transports;
88
89     public String JavaDoc getDomainName() {
90         return this.domainName;
91     }
92
93     public String JavaDoc getServiceName() {
94         return this.serviceName;
95     }
96
97     public String JavaDoc getServiceType() {
98         return this.serviceType;
99     }
100
101 // public boolean isAdd() {
102
// return this.add;
103
// }
104

105     public byte getOperation() {
106         return this.operation;
107     }
108
109     public Set JavaDoc getActors() {
110         return this.transports.getUnderlineMap().keySet();
111     }
112
113     public List JavaDoc getTransports(ServiceActor agent) {
114         return (List JavaDoc) this.transports.get(agent);
115     }
116
117     public void setDomainName(String JavaDoc domainName) {
118         this.domainName = domainName;
119     }
120
121     public void setServiceName(String JavaDoc serviceName) {
122         this.serviceName = serviceName;
123     }
124
125     public void setServiceType(String JavaDoc serviceType) {
126         this.serviceType = serviceType;
127     }
128
129 // public void setAdd(boolean add) {
130
// this.add = add;
131
// }
132

133     public void setOperation(byte operation) {
134         this.operation = operation;
135     }
136
137 // public void setAgents(List agents) {
138
// this.agents = new ByteableList(agents);
139
// }
140

141     public void setTransports(ServiceActor agent, List JavaDoc transports) {
142         if (this.transports == null) {
143             this.transports = new ByteableMap();
144         }
145         this.transports.put(agent, transports == null ? null :
146                             new ByteableList(transports));
147     }
148
149     public void setTransports(ByteableMap transports) {
150         this.transports = transports;
151     }
152
153     public String JavaDoc getByteableName() {
154         return "org.mr.indexing.messages.ServiceParticipationChanged";
155     }
156
157     public void toBytes(ByteableOutputStream out) throws IOException JavaDoc {
158         out.writeASCIIString(this.domainName);
159         out.writeASCIIString(this.serviceName);
160         out.writeASCIIString(this.serviceType);
161 // out.writeASCIIString(this.serviceRole);
162
// out.writeBoolean(this.add);
163
out.writeByte(this.operation);
164 // out.writeByteable(this.agents);
165
out.writeByteable(this.transports);
166     }
167     
168     public Byteable createInstance(ByteableInputStream in) throws IOException JavaDoc {
169         ServiceParticipationChanged result = new ServiceParticipationChanged();
170         result.setDomainName(in.readASCIIString());
171         result.setServiceName(in.readASCIIString());
172         result.setServiceType(in.readASCIIString());
173 // result.setServiceRole(in.readASCIIString());
174
// result.setAdd(in.readBoolean());
175
result.setOperation(in.readByte());
176         result.setTransports((ByteableMap) in.readByteable());
177         return result;
178     }
179
180     public void registerToByteableRegistry() {
181         ByteableRegistry.registerByteableFactory(getByteableName(), this);
182     }
183
184     public static void register() {
185         ServiceParticipationChanged instance =
186             new ServiceParticipationChanged();
187         instance.registerToByteableRegistry();
188     }
189
190     public String JavaDoc toString() {
191         if (serviceName == null) {
192             return "MWB:SPC (null)";
193         } else {
194             return "MWB:SPC op " + operation + " " +
195                 serviceName + " " + transports.getUnderlineMap().size() +
196                 " actors";
197         }
198     }
199
200     public String JavaDoc detailedToString() {
201         if (serviceName == null) {
202             return "MWB:SPC (null)";
203         } else {
204             StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
205             ret.append("MWB:SPC op ").append(operation).
206                 append(" ").append(serviceName);
207             Iterator JavaDoc i = transports.getUnderlineMap().keySet().iterator();
208             while (i.hasNext()) {
209                 ret.append(" ").append(i.next());
210             }
211             return ret.toString();
212         }
213     }
214
215     public static final String JavaDoc getTypeString() {
216         return typeString;
217     }
218 } // ServiceParticipationChanged
219
Popular Tags