KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > control > ControlSignal


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 22, 2004
48  * Manta LTD
49  */

50 package org.mr.kernel.control;
51
52 import java.io.IOException 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.ByteableMap;
57 import org.mr.core.util.byteable.ByteableOutputStream;
58 import org.mr.core.util.byteable.ByteableRegistry;
59
60
61 /**
62  * used to pass control info like dequeue requests and advertise info
63  * Created Jan 22, 2004
64  * Ver 1.0
65  * @author Amir Shevat
66  *
67  */

68 public class ControlSignal implements Byteable {
69     
70     public static final byte OPERATION_TYPE_RECALL =1;
71     public static final byte OPERATION_TYPE_ADVERTISE =2;
72     public static final byte OPERATION_TYPE_UPDATE_SERVICE_ACTOR_STATE =3;
73     public static final byte OPERATION_TYPE_QUEUE_REGISTER =4;
74     public static final byte OPERATION_TYPE_QUEUE_UNREGISTER =5;
75     public static final byte OPERATION_TYPE_GET_QUEUE_COPY =6;
76     public static final byte OPERATION_TYPE_ENQUEUE =7;
77     public static final byte OPERATION_TYPE_GET_MANAGEMENT_PROPERTIES =8;
78     public static final byte OPERATION_TYPE_UNSUBSCRIBE_DURABLE =9;
79     
80     
81     public static final String JavaDoc SERVICE_ACTORS_UPDATE_KEY = "serviceAcotrsUpdateKey";
82     public static final String JavaDoc NUMBER_OF_RECEIVE_ON_QUEUE_KEY ="receiveNum";
83     public static final String JavaDoc SERVICE_UPDATE_NEEDED = "updatedNeeded";
84     public static final String JavaDoc ENQUEUED_MESSAGE = "enqueueMsg";
85     public static final String JavaDoc JMX_RMI_PORT="JMXrmiPort";
86     public static final String JavaDoc JMX_HTTP_PORT="JMXhttpPort";
87     public static final String JavaDoc MANAGEABLE_LAYER="manageable";
88     public static final String JavaDoc MANTA_VERSION = "mantaVersion";
89     public static final String JavaDoc LAYER_TYPE = "layerType";
90     
91     
92     public static volatile long controlIdRunningCount = ControlSignalMessageConsumer.START_CONTROL_SIGNAL_ID-1;
93     
94     private byte operation ;
95     
96     private long controlId;
97     
98     private ByteableMap params = new ByteableMap();
99
100     
101     
102     
103     public ControlSignal(byte operation){
104         this.operation = operation;
105         this.controlId = createControlId();
106         
107     }
108     
109     private synchronized long createControlId(){
110         controlIdRunningCount ++;
111         return controlIdRunningCount;
112     }
113     
114     /**
115      * @return Returns the operation.
116      */

117     public byte getOperation() {
118         return operation;
119     }
120
121     /**
122      * @param operation The operation to set.
123      */

124     public void setOperation(byte operation) {
125         this.operation = operation;
126     }
127
128     /**
129      * @return Returns the params.
130      */

131     public ByteableMap getParams() {
132         return params;
133     }
134
135     /**
136      * @param params The params to set.
137      */

138     public void setParams(ByteableMap params) {
139         this.params = params;
140     }
141     
142     public String JavaDoc toString(){
143         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
144         buff.append("ControlSignal{ operation=");
145         buff.append(operation);
146         buff.append(" controlId=");
147         buff.append(controlId);
148         buff.append(" params=");
149         buff.append(params);
150         return buff.toString();
151     }
152
153     /**
154      * @return Returns the controlId.
155      */

156     public long getControlId() {
157         return controlId;
158     }
159
160     /* (non-Javadoc)
161      * @see org.mr.core.util.byteable.Byteable#getByteableName()
162      */

163     public String JavaDoc getByteableName() {
164         return "ContSig";
165     }
166
167     /* (non-Javadoc)
168      * @see org.mr.core.util.byteable.Byteable#toBytes(org.mr.core.util.byteable.ByteableOutputStream)
169      */

170     public void toBytes(ByteableOutputStream out) throws IOException JavaDoc {
171         out.writeByte(operation);
172         out.writeLong(controlId);
173         out.writeByteable(params);
174         
175         
176         
177     }
178
179     /* (non-Javadoc)
180      * @see org.mr.core.util.byteable.Byteable#createInstance(org.mr.core.util.byteable.ByteableInputStream)
181      */

182     public Byteable createInstance(ByteableInputStream in) throws IOException JavaDoc {
183         byte operation = in.readByte();
184         ControlSignal result = new ControlSignal(operation );
185         result.controlId = in.readLong();
186         result.params =(ByteableMap) in.readByteable();
187         return result;
188     }
189
190     /* (non-Javadoc)
191      * @see org.mr.core.util.byteable.Byteable#registerToByteableRegistry()
192      */

193     public void registerToByteableRegistry() {
194         ByteableRegistry.registerByteableFactory(getByteableName() , this);
195     }
196     
197     public static void register(){
198         ControlSignal instance = new ControlSignal((byte)0);
199         instance.registerToByteableRegistry();
200     }
201
202     
203
204 }
205
Popular Tags