int main (int argc, char *argv[]) { try { BaseTestCase::startTest(argv); XoramAdmin* admin = new XoramAdmin(); admin->connect("root", "root", 60); // create "anonymous" user admin->createUser("anonymous", "anonymous"); admin->disconnect(); ConnectionFactory* cf = new TCPConnectionFactory("localhost", 16010); Connection* cnx = cf->createConnection("anonymous", "anonymous"); printf("##### Cnx state(1): %d\n", cnx->isStopped()); cnx->start(); printf("##### Cnx state(0): %d\n", cnx->isStopped()); cnx->stop(); printf("##### Cnx state(1): %d\n", cnx->isStopped()); cnx->start(); printf("##### Cnx state(0): %d\n", cnx->isStopped()); cnx->close(); } catch (Exception exc) { printf("##### exception - %s", exc.getMessage()); BaseTestCase::error(&exc); } catch (...) { printf("##### exception\n"); BaseTestCase::error(new Exception(" catch ..., unknown exception ")); } printf("##### bye\n"); BaseTestCase::endTest(); }
CMSLogger * CMSLogger::getLog(const std::string& source) { CMSLogger * l = loggers[source]; if (l == NULL) { // First, check if we need to set up connection if (connection == NULL) { try { ConnectionFactory* factory = new activemq::core::ActiveMQConnectionFactory(DEFAULT_CMS_URL, DEFAULT_CMS_USER, DEFAULT_CMS_PASSWORD); connection = factory->createConnection(); delete factory; session = connection->createSession(Session::AUTO_ACKNOWLEDGE); connection->start(); assert(connection != NULL); assert(session != NULL); } catch(CMSException & exc) { std::cerr << "Cannot set up CMS logger connection and session: " << exc.getStackTraceString() << std::endl; } } l = new CMSLogger(source); loggers[source] = l; } assert(l != NULL); return l; }
int main(int argc, char *argv[]) { try { BaseTestCase::startTest(argv); // create Admin and connect XoramAdmin* admin = new XoramAdmin(); admin->connect("root", "root", 60); // create destination Queue* queue = admin->createQueue("queue"); printf("queue->getUID() = %s, queue->getName() = %s\n",queue->getUID(), queue->getName()); Topic* topic = admin->createTopic("topic"); printf("topic->getUID() = %s, topic->getName() = %s\n",topic->getUID(), topic->getName()); // set right admin->setFreeReading(queue); admin->setFreeWriting(queue); admin->setFreeReading(topic); admin->setFreeWriting(topic); // create "anonymous" user admin->createUser("anonymous", "anonymous"); ConnectionFactory* cf = new TCPConnectionFactory("localhost", 16010); Connection* cnx = cf->createConnection("anonymous", "anonymous"); cnx->start(); Session* sess = cnx->createSession(); MessageProducer* prod1 = sess->createProducer(queue); MessageProducer* prod2 = sess->createProducer(topic); MessageConsumer* cons1 = sess->createConsumer(queue); MessageConsumer* cons2 = sess->createConsumer(topic); Message* msg1 = sess->createMessage(); prod1->send(msg1); printf("##### Message sent on queue: %s\n", msg1->getMessageID()); Message* msg2 = sess->createMessage(); prod2->send(msg2); printf("##### Message sent on topic: %s\n", msg2->getMessageID()); Message* msg = cons1->receive(); printf("##### Message received from queue: %s\n", msg->getMessageID()); msg = cons2->receive(); printf("##### Message received from tpoic: %s\n", msg->getMessageID()); // delete User CreateUserReply* userReply = admin->createUser("removeUser", "removeUser"); admin->deleteUser("removeUser",userReply->getProxId()); // delete Queue and Topic printf("delete Queue %s\n", queue->getUID()); admin->deleteDestination(queue->getUID()); printf("delete Topic %s\n", topic->getUID()); admin->deleteDestination(topic->getUID()); admin->disconnect(); cnx->close(); } catch (Exception exc) { printf("##### exception - %s", exc.getMessage()); BaseTestCase::error(&exc); } catch (...) { printf("##### exception\n"); BaseTestCase::error(new Exception(" catch ..., unknown exception ")); } printf("##### bye\n"); BaseTestCase::endTest(); }
// Init status_t ServerConnection::Init(vnode_id connectionBrokenTarget) { if (!fServerInfo) RETURN_ERROR(B_BAD_VALUE); // create a connection broken event fConnectionBrokenEvent = new(std::nothrow) ConnectionBrokenEvent(connectionBrokenTarget); if (!fConnectionBrokenEvent) return B_NO_MEMORY; // get the server address const char* connectionMethod = fServerInfo->GetConnectionMethod(); HashString server; status_t error = fServerInfo->GetAddress().GetString(&server, false); if (error != B_OK) RETURN_ERROR(error); // create the volume map fVolumes = new(std::nothrow) VolumeMap; if (!fVolumes) RETURN_ERROR(B_NO_MEMORY); error = fVolumes->InitCheck(); if (error != B_OK) RETURN_ERROR(error); // establish the connection Connection* connection; ConnectionFactory factory; error = factory.CreateConnection(connectionMethod, server.GetString(), &connection); if (error != B_OK) RETURN_ERROR(error); // create a request connection fConnection = new(std::nothrow) RequestConnection(connection, this); if (!fConnection) { delete connection; RETURN_ERROR(B_NO_MEMORY); } error = fConnection->Init(); if (error != B_OK) return error; // send an `init connection request' // prepare the request InitConnectionRequest request; request.bigEndian = B_HOST_IS_BENDIAN; // send the request Request* _reply; error = fConnection->SendRequest(&request, &_reply); if (error != B_OK) return error; ObjectDeleter<Request> replyDeleter(_reply); // everything OK? InitConnectionReply* reply = dynamic_cast<InitConnectionReply*>(_reply); if (!reply) return B_BAD_DATA; if (reply->error != B_OK) return reply->error; fConnected = true; return B_OK; }