KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > services > ServiceActor


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 Amir Shevat.
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  * Created on Jan 20, 2004
48  * Manta LTD
49  */

50 package org.mr.kernel.services;
51
52
53
54 import org.mr.kernel.UniqueIDGenerator;
55 import org.mr.core.net.MantaAddress;
56
57 /**
58  *
59  * a super class for ServiceConsumer and ServiceProducer and other service roles
60  * @since Jan 20, 2004
61  * @version 1.0
62  * @author Amir Shevat
63  *
64  *
65  */

66 public abstract class ServiceActor implements MantaAddress{//, Serializable{
67
/**
68      * byte for CONSUMER type
69      */

70     public static final byte CONSUMER =1;
71     /**
72      * byte for PRODUCER type
73      */

74     public static final byte PRODUCER =2;
75     /**
76      * byte for COORDINATOR
77      */

78      public static final byte COORDINATOR =3;
79     
80     /**
81      * the name of the agent this actor was created in
82      */

83     private String JavaDoc agentName;
84     /**
85      * the name of the agent this actor was created in
86      */

87     private String JavaDoc domainName;
88     /**
89      * the name of the service this actor belongs too
90      */

91     private String JavaDoc serviceName;
92     
93     /**
94      * one of MantaService SERVICE_TYPE_QUEUE or SERVICE_TYPE_TOPIC
95      */

96     private byte serviceType;
97     
98     /**
99      * the id of the message
100      */

101     protected String JavaDoc id;
102     
103     
104     
105     public ServiceActor(String JavaDoc agentName, String JavaDoc domainName, String JavaDoc serviceName , byte serviceType){
106         this.agentName = agentName;
107         this.domainName = domainName;
108         this.serviceName = serviceName;
109         this.serviceType = serviceType;
110         StringBuffer JavaDoc idBuf = new StringBuffer JavaDoc();
111         idBuf.append(agentName);
112         idBuf.append("@");
113         idBuf.append(serviceName);
114         idBuf.append(serviceType);
115         idBuf.append(getType());
116         idBuf.append(UniqueIDGenerator.getNextMessageID());
117         this.id = idBuf.toString();
118     }
119     
120     public void setID(String JavaDoc id){
121         this.id = id;
122     }
123
124     /**
125      * @return Returns the type.
126      */

127     public abstract byte getType();
128     
129
130     /**
131      * @return Returns the actorName.
132      */

133     public String JavaDoc getAgentName() {
134         return agentName;
135     }
136
137     /**
138      * @return Returns the domain name (optional operation, not implemented).
139      */

140     public String JavaDoc getDomainName() {
141         return this.domainName;
142     }
143
144     /**
145      * @param actorName The actorName to set.
146      */

147     public void setAgentName(String JavaDoc actorName) {
148         this.agentName = actorName;
149     }
150     /**
151      * @return the string representation of the object
152      */

153     public String JavaDoc toString(){
154         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
155         buff.append("ServiceActor{ service=");
156         buff.append(getServiceName());
157         buff.append(" id=");
158         buff.append(getId());
159         buff.append(" type=");
160         buff.append(getType());
161         return buff.toString();
162     }
163
164     /**
165      * @return Returns the service name of this actor.
166      */

167     public String JavaDoc getServiceName() {
168         return serviceName;
169     }
170
171     
172
173     
174     /**
175      * @return Returns the id.
176      */

177     public String JavaDoc getId() {
178         
179         return id;
180     }
181     
182     /**
183      * @return true if other object is ServiceActor and has the same ID
184      */

185     public boolean equals(Object JavaDoc obj){
186         if(this == obj) return true;
187         if (obj instanceof ServiceActor){
188             ServiceActor other = (ServiceActor)obj;
189             if(other.getId().equalsIgnoreCase(this.getId())){
190                 return true;
191             }
192                 
193         }
194         return false;
195     }
196     
197     public int hashCode(){
198         //Amir - >AMIR
199
return this.getId().toUpperCase().hashCode();
200     }
201
202
203     public byte getServiceType() {
204         return serviceType;
205     }
206 }
207
Popular Tags