Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
    // get and set locale language
	string systemLang = "C";
	systemLang = funcexp::utf8::idb_setlocale();

    setupCwd();

    WriteEngine::WriteEngineWrapper::init( WriteEngine::SUBSYSTEM_ID_DDLPROC );
#ifdef _MSC_VER
    // In windows, initializing the wrapper (A dll) does not set the static variables
    // in the main program
    idbdatafile::IDBPolicy::configIDBPolicy();
#endif

	ResourceManager rm;
	Dec = DistributedEngineComm::instance(rm);
#ifndef _MSC_VER
	/* set up some signal handlers */
    struct sigaction ign;
    memset(&ign, 0, sizeof(ign));
    ign.sa_handler = added_a_pm;
	sigaction(SIGHUP, &ign, 0);
	ign.sa_handler = SIG_IGN;
	sigaction(SIGPIPE, &ign, 0);
#endif

    ddlprocessor::DDLProcessor ddlprocessor(5, 10);

    {
        Oam oam;
        try
        {
            oam.processInitComplete("DDLProc", ACTIVE);
        }
        catch (...)
        {
        }
    }

    try
    {
        ddlprocessor.process();
    }
    catch (std::exception& ex)
    {
        cerr << ex.what() << endl;
        Message::Args args;
        Message message(8);
        args.add("DDLProc failed on: ");
        args.add(ex.what());
        message.format( args );

    }
    catch (...)
    {
        cerr << "Caught unknown exception!" << endl;
        Message::Args args;
        Message message(8);
        args.add("DDLProc failed on: ");
        args.add("receiving DDLPackage");
        message.format( args );
    }
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	// get and set locale language
    string systemLang = "C";
	systemLang = funcexp::utf8::idb_setlocale();

    printf ("Locale is : %s\n", systemLang.c_str() );

	//set BUSY_INIT state
	{
		// Is there a reason to have a seperate Oam instance for this?
		Oam oam;
		try
		{
			oam.processInitComplete("WriteEngineServer", oam::BUSY_INIT);
		}
		catch (...)
		{
		}
	}
	//BUG 2991
	setlocale(LC_NUMERIC, "C");
#ifndef _MSC_VER
	struct sigaction sa;
	memset(&sa, 0, sizeof(sa));
    sa.sa_handler = added_a_pm;
	sigaction(SIGHUP, &sa, 0);
	sa.sa_handler = SIG_IGN;
	sigaction(SIGPIPE, &sa, 0);
#endif

	// Init WriteEngine Wrapper (including Config Calpont.xml cache)
	WriteEngine::WriteEngineWrapper::init( WriteEngine::SUBSYSTEM_ID_WE_SRV );

#ifdef _MSC_VER
    // In windows, initializing the wrapper (A dll) does not set the static variables
    // in the main program
    idbdatafile::IDBPolicy::configIDBPolicy();
#endif
	Config weConfig;
	int rc;
	rc = setupResources();
	
	ostringstream serverParms;
	serverParms << "pm" << weConfig.getLocalModuleID() << "_WriteEngineServer";

	// Create MessageQueueServer, with one retry in case the call to bind the
	// known port fails with "Address already in use".
	boost::scoped_ptr<MessageQueueServer> mqs;
	bool tellUser = true;
	for (;;)
	{
		try {
			mqs.reset(new MessageQueueServer(serverParms.str()));
			break;
		}
		// @bug4393 Error Handling for MessageQueueServer constructor exception
		catch (runtime_error& re) {
			string what = re.what();
			if (what.find("Address already in use") != string::npos)
			{
				if (tellUser)
				{
					cerr << "Address already in use, retrying..." << endl;
					tellUser = false;
				}
				sleep(5);
			}
			else
			{
				Oam oam;
				try // Get out of BUSYINIT state; else OAM will not retry
				{
					oam.processInitComplete("WriteEngineServer");
				}
				catch (...)
				{
				}

				// If/when a common logging class or function is added to the
				// WriteEngineServer, we should use that.  In the mean time,
				// I will log this errmsg with inline calls to the logging.
				logging::Message::Args args;
				logging::Message message;
				string errMsg("WriteEngineServer failed to initiate: ");
				errMsg += what;
				args.add( errMsg );
				message.format(args);
				logging::LoggingID lid(SUBSYSTEM_ID_WE_SRV);
				logging::MessageLog ml(lid);
				ml.logCriticalMessage( message );

				return 2;
			}
		}
	}

	IOSocket ios;
	size_t mt = 20;
	size_t qs = mt * 100;
	ThreadPool tp(mt, qs);

	//set ACTIVE state
	{
		Oam oam;
		try
		{
			oam.processInitComplete("WriteEngineServer", ACTIVE);
		}
		catch (...)
		{
		}
	}
	cout << "WriteEngineServer is ready" << endl;
	BRM::DBRM dbrm;
	for (;;)
	{
		try // BUG 4834 -
		{
			ios = mqs->accept();
			//tp.invoke(ReadThread(ios));
			ReadThreadFactory::CreateReadThread(tp,ios, dbrm);
			{
/*				logging::Message::Args args;
				logging::Message message;
				string aMsg("WriteEngineServer : New incoming connection");
				args.add(aMsg);
				message.format(args);
				logging::LoggingID lid(SUBSYSTEM_ID_WE_SRV);
				logging::MessageLog ml(lid);
				ml.logInfoMessage( message ); */
			}
		}
		catch(std::exception& ex) // BUG 4834 - log the exception
		{
			logging::Message::Args args;
			logging::Message message;
			string errMsg("WriteEngineServer : Exception caught on accept(): ");
			errMsg += ex.what();
			args.add( errMsg );
			message.format(args);
			logging::LoggingID lid(SUBSYSTEM_ID_WE_SRV);
			logging::MessageLog ml(lid);
			ml.logCriticalMessage( message );
			break;
		}
	}

	//It is an error to reach here...
	return 1;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
    // get and set locale language
	string systemLang = "C";

	BRM::DBRM dbrm;
    Oam oam;
	//BUG 5362
	systemLang = funcexp::utf8::idb_setlocale();

    Config* cf = Config::makeConfig();

    setupCwd();

    WriteEngine::WriteEngineWrapper::init( WriteEngine::SUBSYSTEM_ID_DMLPROC );
#ifdef _MSC_VER
    // In windows, initializing the wrapper (A dll) does not set the static variables
    // in the main program
    idbdatafile::IDBPolicy::configIDBPolicy();
#endif
	
    try
    {
		// At first we set to BUSY_INIT
		oam.processInitComplete("DMLProc", oam::BUSY_INIT);
    }
    catch (...)
    {
    }
	
	//@Bug 1627
	try 
	{
    	rollbackAll(&dbrm); // Rollback any 
	}
	catch ( std::exception &e )
	{
		//@Bug 2299 Set DMLProc process to fail and log a message 
		try
		{
			oam.processInitFailure();
		}
		catch (...)
        {
        } 
		logging::Message::Args args;
        logging::Message message(2);
        args.add("DMLProc failed to start due to :");
		args.add(e.what());
        message.format( args );
		logging::LoggingID lid(20);
        logging::MessageLog ml(lid);

        ml.logCriticalMessage( message );
		
		cerr << "DMLProc failed to start due to : " << e.what() << endl;
		return 1;
	}

	int temp;
	int serverThreads = 10;
	int serverQueueSize = 50;
	const string DMLProc("DMLProc");
	
	temp = toInt(cf->getConfig(DMLProc, "ServerThreads"));
	if (temp > 0)
			serverThreads = temp;

	temp = toInt(cf->getConfig(DMLProc, "ServerQueueSize"));
	if (temp > 0)
			serverQueueSize = temp;


    bool rootUser = true;
#ifndef _MSC_VER
    //check if root-user
    int user;
    user = getuid();
    if (user != 0)
        rootUser = false;
#endif
    //read and cleanup port before trying to use
    try {
        string port = cf->getConfig(DMLProc, "Port");
        string cmd = "fuser -k " + port + "/tcp >/dev/null 2>&1";
        if ( !rootUser)
            cmd = "sudo fuser -k " + port + "/tcp >/dev/null 2>&1";

        (void)::system(cmd.c_str());
    }
    catch(...)
    {
    }

	DMLServer dmlserver(serverThreads, serverQueueSize,&dbrm);

	//set ACTIVE state
    try
    {
        oam.processInitComplete("DMLProc", ACTIVE);
    }
    catch (...)
    {
    }
	ResourceManager rm;
	Dec = DistributedEngineComm::instance(rm);

#ifndef _MSC_VER
	/* set up some signal handlers */
    struct sigaction ign;
    memset(&ign, 0, sizeof(ign));
    ign.sa_handler = added_a_pm;
	sigaction(SIGHUP, &ign, 0);
	ign.sa_handler = SIG_IGN;
	sigaction(SIGPIPE, &ign, 0);
#endif

    dmlserver.start();

    return 1;
}