00001 /******************************************************************************* 00002 00003 @file RollCall.d 00004 00005 Copyright (C) 2004 Kris Bell 00006 00007 This software is provided 'as-is', without any express or implied 00008 warranty. In no event will the authors be held liable for damages 00009 of any kind arising from the use of this software. 00010 00011 Permission is hereby granted to anyone to use this software for any 00012 purpose, including commercial applications, and to alter it and/or 00013 redistribute it freely, subject to the following restrictions: 00014 00015 1. The origin of this software must not be misrepresented; you must 00016 not claim that you wrote the original software. If you use this 00017 software in a product, an acknowledgment within documentation of 00018 said product would be appreciated but is not required. 00019 00020 2. Altered source versions must be plainly marked as such, and must 00021 not be misrepresented as being the original software. 00022 00023 3. This notice may not be removed or altered from any distribution 00024 of the source. 00025 00026 00027 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00028 00029 00030 @version Initial version, July 2004 00031 @author Kris 00032 00033 00034 *******************************************************************************/ 00035 00036 module mango.cluster.qos.socket.RollCall; 00037 00038 private import mango.cache.Payload; 00039 00040 /****************************************************************************** 00041 00042 An IPayload used by the cluster client and server during discovery 00043 lookup and liveness broadcasts. The client broadcasts one of these 00044 at startup to see which servers are alive. The server responds with 00045 a reply RollCall stating its name and port. The server will also 00046 broadcast one of these when it first starts, such that any running 00047 clients can tell the server has 'recovered'. 00048 00049 ******************************************************************************/ 00050 00051 class RollCall : Payload 00052 { 00053 char[] name; 00054 int port1, 00055 port2; 00056 bool request; 00057 00058 private import mango.io.PickleRegistry; 00059 00060 /*********************************************************************** 00061 00062 Register this class for pickling, so we can resurrect 00063 instances when they arrive on a network datagram. 00064 00065 ***********************************************************************/ 00066 00067 static this () 00068 { 00069 PickleRegistry.enroll (new RollCall); 00070 } 00071 00072 /********************************************************************** 00073 00074 **********************************************************************/ 00075 00076 this () 00077 { 00078 } 00079 00080 /********************************************************************** 00081 00082 **********************************************************************/ 00083 00084 this (char[] name, ushort port1, ushort port2, bool request = false) 00085 { 00086 this.name = name; 00087 this.port1 = port1; 00088 this.port2 = port2; 00089 this.request = request; 00090 } 00091 00092 /********************************************************************** 00093 00094 **********************************************************************/ 00095 00096 void read (IReader reader) 00097 { 00098 super.read (reader); 00099 reader.get (name) 00100 .get (port1) 00101 .get (port2) 00102 .get (request); 00103 } 00104 00105 /********************************************************************** 00106 00107 **********************************************************************/ 00108 00109 void write (IWriter writer) 00110 { 00111 super.write (writer); 00112 writer.put (name) 00113 .put (port1) 00114 .put (port2) 00115 .put (request); 00116 } 00117 00118 /********************************************************************** 00119 00120 **********************************************************************/ 00121 00122 override Payload create () 00123 { 00124 return new RollCall; 00125 } 00126 00127 /********************************************************************** 00128 00129 **********************************************************************/ 00130 00131 override char[] getGuid () 00132 { 00133 return this.classinfo.name; 00134 } 00135 } 00136 00137