📄 redundancymanager.hxx
字号:
#ifndef REDUNDANTCYMANAGER_HXX#define REDUNDANTCYMANAGER_HXX/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const RedundancyManager_hxx_Version = "$Id: RedundancyManager.hxx,v 1.5 2002/09/26 01:14:03 bko Exp $";// #include "NetworkAddress.h"#include "FileDataStore.hxx"#include "RegisterManager.hxx"#include "LockHelper.hxx"class NetworkAddress;/** Class to maintain information/communicate with redundant server THIS CLASS SHOULD NOT BE INSTANCIATED DIRECTLY! It is part of the ProvisioningServer*/class RedundancyManager{ public: // Possible states static const int DNSYNC = 0; // Dead, not synched static const int ANSYNC = 1; // Alive, not synched static const int ASLAVE = 9; // Alive, slave in sync static const int AMASTER = 5; // Alive, master in sync static const int ASYNC = 3; // Alive, snyched // return codes when state changes static const int ERR = -1; // error (now in invalud state) static const int OK = 0; // send OK message static const int FAIL = 1; // send FAIL message (and set sync clock) static const int NMSG = 2; // ok, send no message /// Constructor RedundancyManager(); /// Destructor ~RedundancyManager() { } /// intialize with a host and port void initialize(const string &host, int port, bool useTls = true); /// string className() { return "RedundancyManager"; } /// accessors string getHostName() { return _host; } /// int getPort() { return _port; } /// write an item to the redundant server (SYNCPUT) int writeItem(const string &group, const string &name, const string &contents, TimeStamp timestamp); /// read an item from the redundant server (SYNCGET) int readItem(const string &group, const string &name, string &contents, TimeStamp ×tamp); /// Send a SYNCUNREGISTER to twin int sendUnregisterItem(const string &group, const string &name, const string &host); /// Send a SYNCUNREGISTER for a group to twin int sendUnregisterGroup(const string &group, const string &host); /// Send a SYNCREGISTER to twin int sendRegisterItem(const string &group, const string &name, const string &host); /// Send a SYNCREGISTER for a group to twin int sendRegisterGroup(const string &group, const string &host); /// Send a remote sync to the remote host and get back the list as a map int getRemoteMap(map < string, TimeStamp > &remote); /// Send a SYNCDEL to twin int sendDeleteItem(const string &group, const string &name); /// get the remote registrations and register them int getRemoteRegistration(RegisterManager &man); /// Send our registration int putLocalRegistration(RegisterManager &man); /// Send a SYNCGOOD int sendGood(); /// Sync aborted/failed int abortSync(); /// Sync timed out int timedoutSync(); /// we just lost heartbeat. If not invalid, switch to dead no sync int heartBeatGone(); /// Hearbeat. If not dead, ignore if in good state. If dead, go live int heartBeat(); /// Got back a bad message from a sync command, go to ASYNC int badReturn(); /// Failed on a write to our twin. Go to dead/non-synced int connFailed(); /** Got a sync start message from other. Switch to slave state if alive not synched */ int syncStart(); /// got a sync finished int syncGood(); /// this is a SYNCGET/SYNCPUT message. int syncExchange(); /// we want to start a sync (will be master) int startSync(); /// get/put list of registered clients int syncRegList(); // accessors to the bits /// bool isAlive(); /// bool isSync(); /// bool isMaster(); /// bool isSlave(); /// Are we using redundancy? bool inUse() { return _use; } private: /// there are only 5 of the 16 states that are legal -- are we in one? bool checkState(); int _state; // state of the machine bool _use; // internal mask for the bits static const int ALIVE = 1; static const int SYNC = 2; static const int MASTER = 4; static const int SLAVE = 8; string _host; int _port; // Try LockHelper instead // pthread_mutex_t _lock; VMutex _aMutex; /// network address of the redundant server NetworkAddress *_networkAddress; /// set to true if you want to use TLS (default == true bool myUseTls;};/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -