int main()

in src/utils/deployCppService.cpp [47:213]


int main(int argc, char* argv[]) {
 // cout << "=====================================================\n";    
  cout << __FILE__ << " Starting the UIMA C++ Remote Service using ActiveMQ broker." << std::endl;
 // cout << "-----------------------------------------------------\n";
  // _CrtSetBreakAlloc(1988);
  activemq::library::ActiveMQCPP::initializeLibrary();
  std::cout << "Running with ActiveMQ CPP failover enabled. " << std::endl;
  try {
    if (argc < 3) {
      printUsage();
      return(-1);
    }

    /* create ResourceManager */
    if (!uima::ResourceManager::hasInstance()) {
      uima::ResourceManager::createInstance("ActiveMQAnalysisEngineService");
    }

    /* APR pool */
    apr_status_t rv;
    apr_pool_t *pool;
    rv = apr_pool_create(&pool, NULL);
    if (rv != APR_SUCCESS) {
      cerr << __FILE__ << " ERROR: apr_pool_create() failed. " << endl;
      return -1;
    }


    /*parse descriptor */
    ServiceParameters serviceDesc;
    serviceDesc.parseArgs(argc, argv);
    serviceDesc.print();

    /*set up logging and monitoring */
    initialize(serviceDesc, pool);   

    /*create service*/
    AMQAnalysisEngineService aeService(serviceDesc,singleton_pMonitor, pool);
    aeService.setTraceLevel(serviceDesc.getTraceLevel());

    /* create processing threads */
    aeService.startProcessingThreads();

    /*start receiving messages*/ 
    cerr << __FILE__ << __LINE__  << " Start receiving messages " << endl;
    aeService.start();

    //check if java process still there
   

    cerr << __FILE__ << " UIMA C++ Service " << serviceDesc.getQueueName() << " at " <<
    serviceDesc.getBrokerURL() << " Ready to process..." << endl;
    
    /* connect to java proxy if called from java */  
    apr_thread_t *thread=0;
    apr_threadattr_t *thd_attr=0;

    if (cs) {
      apr_threadattr_create(&thd_attr, pool);
      rv = apr_thread_create(&thread, thd_attr, handleCommands, 0, pool);
      assert(rv == APR_SUCCESS);
      //rv = apr_thread_join(&rv, thread);
      //assert(rv == APR_SUCCESS);
      apr_thread_mutex_lock(singleton_pMonitor->cond_mutex);
      apr_thread_cond_wait(singleton_pMonitor->cond, singleton_pMonitor->cond_mutex);
      apr_thread_mutex_unlock(singleton_pMonitor->cond_mutex);

    }  else {
      uima::ResourceManager::getInstance().getLogger().logError(" not from java running ");
      apr_thread_t *stdinthread=0;
      rv = apr_thread_create(&stdinthread, thd_attr, readstdin, 0, pool);
      rv = apr_thread_join(&rv, stdinthread);
    }  

    //wait
/**    if (cs) { 
      apr_thread_mutex_lock(singleton_pMonitor->cond_mutex);
      apr_thread_cond_wait(singleton_pMonitor->cond, singleton_pMonitor->cond_mutex);
      apr_thread_mutex_unlock(singleton_pMonitor->cond_mutex);    
    }
**/
    if (singleton_pMonitor->getQuiesceAndStop()) {
      cerr << __FILE__ << " " << serviceDesc.getServiceName() << " Quiesce started. " << endl;
      //quiesce 
      aeService.quiesceAndStop();
      cerr << __FILE__ << " " << serviceDesc.getServiceName() << " quiesced. " << endl;
    } else {
      cerr << __FILE__ << " Shutdown started. " << endl;
      aeService.shutdown();
      cerr << __FILE__ << " Shutdown done. " << endl;
    }

    //notify java controller
    if (cs) {
      apr_size_t len = 4;
      apr_status_t rv = apr_socket_send(cs, "DONE" , &len);
      len = 1;
      apr_socket_send(cs,"\n", &len);
      if (rv != APR_SUCCESS) {
        cerr << " apr_socket_send() failed sending shutdown notification." << endl;
      }
    }  

    /* cleanup */
    terminateService();
    
    if (pool) {
      apr_pool_destroy(pool);
      pool=0;
    }
  }  catch (CMSException& e) {
    stringstream str; 
    str << e.getMessage() << endl;
    cerr << __FILE__ << __LINE__ << " " << str.str() << endl;
    /***
    if (cs) {
      apr_size_t len = str.str().length();
      rv = apr_socket_send(cs, str.str().c_str(), &len);
      len = 1;
      apr_socket_send(cs,"\n", &len);
    }
    ***/
  } catch (XMLException& e) {
    stringstream str; 
    str << e.getMessage() << endl;
    cerr << __FILE__ << __LINE__ << " " << str.str() << endl;
    /***
    if (cs) {
      apr_size_t len = str.str().length();
      rv = apr_socket_send(cs, str.str().c_str(), &len);
      len = 1;
      apr_socket_send(cs,"\n", &len);
    }
    ***/
  } catch (uima::Exception e) {
    stringstream str;
    str << e.getErrorInfo().getMessage().asString() << endl;
    cerr << __FILE__ << __LINE__ << " " << str.str() << endl;
    /***
    if (cs) {
      apr_size_t len = str.str().length();
      rv = apr_socket_send(cs, str.str().c_str(), &len);
      len = 1;
      apr_socket_send(cs,"\n", &len);
    }
    ***/
  } catch (...) {
    stringstream str;
    str <<  "Unknown Exception" << endl;
    cerr << __FILE__ << __LINE__ << " " << str.str() << endl;
    /***
    if (cs) {
      apr_size_t len = str.str().length();
      rv = apr_socket_send(cs, str.str().c_str(), &len);
      len = 1;
      apr_socket_send(cs,"\n", &len);
    }
    ***/
  }
  //cout << "-----------------------------------------------------\n";    
  cout << __FILE__ " UIMA C++ Remote Service terminated:\n";
  //cout << "=====================================================\n";    

  activemq::library::ActiveMQCPP::shutdownLibrary();
   exit(0);

}  //main