|
activemq-cpp-3.4.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _ATIVEMQ_UTIL_IDGENERATOR_H_ 00019 #define _ATIVEMQ_UTIL_IDGENERATOR_H_ 00020 00021 #include <activemq/util/Config.h> 00022 00023 #include <string> 00024 00025 namespace activemq { 00026 namespace library { 00027 class ActiveMQCPP; 00028 } 00029 namespace util { 00030 00031 class IdGeneratorKernel; 00032 00033 class AMQCPP_API IdGenerator { 00034 private: 00035 00036 std::string prefix; 00037 mutable std::string seed; 00038 mutable long long sequence; 00039 00040 static IdGeneratorKernel* kernel; 00041 00042 private: 00043 00044 IdGenerator( const IdGenerator& ); 00045 IdGenerator& operator= ( const IdGenerator& ); 00046 00047 public: 00048 00049 IdGenerator(); 00050 00051 IdGenerator( const std::string& prefix ); 00052 00053 virtual ~IdGenerator(); 00054 00055 public: 00056 00060 std::string generateId() const; 00061 00062 public: 00063 00070 static std::string getHostname(); 00071 00077 static std::string getSeedFromId( const std::string& id ); 00078 00084 static long long getSequenceFromId( const std::string& id ); 00085 00096 static int compare( const std::string& id1, const std::string& id2 ); 00097 00098 private: 00099 00100 static void initialize(); 00101 static void shutdown(); 00102 00103 friend class activemq::library::ActiveMQCPP; 00104 }; 00105 00106 }} 00107 00108 #endif /* _ATIVEMQ_UTIL_IDGENERATOR_H_ */