Exemplo n.º 1
0
void SolverMRP::SolverMRPdata::solveSafetyStock(SolverMRP* solver)
{
  OperatorDelete cleanup("sweeper", this);
  safety_stock_planning = true;
  if (getLogLevel()>0) logger << "Start safety stock replenishment pass   " << solver->getConstraints() << endl;
  vector< list<Buffer*> > bufs(HasLevel::getNumberOfLevels() + 1);
  for (Buffer::iterator buf = Buffer::begin(); buf != Buffer::end(); ++buf)
    if (buf->getCluster() == cluster
      && ( buf->getMinimum() || buf->getMinimumCalendar()
        || buf->getType() == *BufferProcure::metadata )
      )
      bufs[(buf->getLevel()>=0) ? buf->getLevel() : 0].push_back(&*buf);
  for (vector< list<Buffer*> >::iterator b_list = bufs.begin(); b_list != bufs.end(); ++b_list)
    for (list<Buffer*>::iterator b = b_list->begin(); b != b_list->end(); ++b)
    {
      state->curBuffer = NULL;
      // A quantity of -1 is a flag for the buffer solver to solve safety stock.
      state->q_qty = -1.0;
      state->q_date = Date::infinitePast;
      state->a_cost = 0.0;
      state->a_penalty = 0.0;
      planningDemand = NULL;
      state->curDemand = NULL;
      state->motive = *b;
      state->curOwnerOpplan = NULL;
      // Call the buffer solver
      (*b)->solve(*solver, this);
      // Check for excess
      if ((*b)->getType() != *BufferProcure::metadata)
        (*b)->solve(cleanup, this);
      CommandManager::commit();
    }
  if (getLogLevel()>0) logger << "Finished safety stock replenishment pass" << endl;
  safety_stock_planning = false;
}
Exemplo n.º 2
0
void LoggerPlugin::openFile()
{
    if (m_bFilter){
        if ((getLogLevel() & L_EVENTS) == 0){
            qApp->removeEventFilter(this);
            m_bFilter = false;
        }
    }else{
        if (getLogLevel() & L_EVENTS){
            qApp->installEventFilter(this);
            m_bFilter = true;
        }
    }
    if (m_file){
        delete m_file;
        m_file = NULL;
    }
    const char *fname = getFile();
    if ((fname == NULL) || (*fname == 0))
        return;
    m_file = new QFile(QFile::decodeName(fname));
    if (!m_file->open(IO_Append | IO_ReadWrite)){
        delete m_file;
        m_file = NULL;
        log(L_WARN, "Can't open %s", fname);
    }
}
Exemplo n.º 3
0
void *LoggerPlugin::processEvent(Event *e)
{
    if (e->type() == EventLog){
        LogInfo *li = (LogInfo*)e->param();
        if (((li->packet_id == 0) && (li->log_level & getLogLevel())) ||
                (li->packet_id && isLogType(li->packet_id))){
            string s;
            s = make_packet_string(li);
            if (m_file){
#ifdef WIN32
                s += "\r\n";
#else
                s += "\n";
#endif
                m_file->writeBlock(s.c_str(), s.length());
            }
#ifdef QT_DLL
            for (char *p = (char*)(s.c_str()); *p; ){
                char *r = strchr(p, '\n');
                if (r) *r = 0;
                qWarning("%s", p);
                if (r == NULL) break;
                p = r + 1;
            }
#else
            fprintf(stderr, "%s", s.c_str());
            fprintf(stderr, "\n");
#endif
        }
    }
    return NULL;
}
Exemplo n.º 4
0
DECLARE_EXPORT void SolverMRP::scanExcess(CommandList* l)
{
  // Loop over all newly created operationplans found in the command stack
  for(CommandList::iterator cmd = l->begin(); cmd != l->end(); ++cmd)
  {
    CommandCreateOperationPlan* createcmd = dynamic_cast<CommandCreateOperationPlan*>(&*cmd);
    if (!createcmd)
    {
      // If the command is a list: recursively call this function
      if (dynamic_cast<CommandList*>(&*cmd))
        scanExcess(dynamic_cast<CommandList*>(&*cmd));
      //else: Not a command creating an operationplan: move on
    }
    else
    {
      // Detect excess operationplans and undo them
      if (createcmd->getOperationPlan() && createcmd->getOperationPlan()->isExcess())
      {
        if (getLogLevel()>1)
          logger << "Denying creation of redundant operationplan "
              << createcmd->getOperationPlan()->getOperation() << "  "
              << createcmd->getOperationPlan()->getDates() << "  "
              << createcmd->getOperationPlan()->getQuantity() << endl;
        createcmd->rollback();
      }
    }
  }
}
Exemplo n.º 5
0
void HTMLStyleElementImp::handleMutation(EventListenerImp* listener, events::Event event)
{
    // TODO: update type, media, and scoped. Then check type.

    events::MutationEvent mutation(interface_cast<events::MutationEvent>(event));

    DocumentImp* document = getOwnerDocumentImp();
    if (!document)
        return;

    if (mutation.getType() == u"DOMNodeRemoved" && event.getTarget().self() == this)
        styleSheet = 0;
    else {
        std::u16string content;
        for (Node node = getFirstChild(); node; node = node.getNextSibling()) {
            if (TextImp* text = dynamic_cast<TextImp*>(node.self()))  // TODO better to avoid imp call?
                content += text->getData();
        }
        CSSParser parser;
        styleSheet = parser.parse(document, content);
        if (auto imp = dynamic_cast<CSSStyleSheetImp*>(styleSheet.self())) {
            imp->setOwnerNode(this);
            if (4 <= getLogLevel())
                dumpStyleSheet(std::cerr, imp);
        }
    }
    if (WindowImp* view = document->getDefaultWindow())
        view->setFlags(Box::NEED_SELECTOR_REMATCHING);
    document->resetStyleSheets();
}
Exemplo n.º 6
0
void *LoggerPlugin::processEvent(Event *e)
{
    if (e->type() == EventLog){
        LogInfo *li = (LogInfo*)e->param();
        if (((li->packet_id == 0) && (li->log_level & getLogLevel())) ||
                (li->packet_id && ((getLogLevel() & L_PACKETS) || isLogType(li->packet_id)))){
            string s;
            s = make_packet_string(li);
            if (m_file){
#ifdef WIN32
                s += "\r\n";
#else
                s += "\n";
#endif
                m_file->writeBlock(s.c_str(), s.length());
            }
#ifdef QT_DLL
            for (char *p = (char*)(s.c_str()); *p; ){
                char *r = strchr(p, '\n');
                if (r) *r = 0;
                if (strlen(p) > 256){
                    string s = p;
                    while (!s.empty()){
                        string l;
                        if (s.length() < 256){
                            l = s;
                            s = "";
                        }else{
                            l = s.substr(0, 256);
                            s = s.substr(256);
                        }
                        qWarning("%s", l.c_str());
                    }
                }else{
                    qWarning("%s", p);
                }
                if (r == NULL) break;
                p = r + 1;
            }
#else
            fprintf(stderr, "%s", s.c_str());
            fprintf(stderr, "\n");
#endif
        }
    }
    return NULL;
}
Exemplo n.º 7
0
DECLARE_EXPORT PyObject* Solver::getattro(const Attribute& attr)
{
  if (attr.isA(Tags::tag_name))
    return PythonObject(getName());
  if (attr.isA(Tags::tag_loglevel))
    return PythonObject(getLogLevel());
  return NULL;
}
Exemplo n.º 8
0
DECLARE_EXPORT void SolverMRP::solve(void *v)
{
  // Count how many clusters we have to plan
  int cl = HasLevel::getNumberOfClusters() + 1;

  // Categorize all demands in their cluster
  demands_per_cluster.resize(cl);
  for (Demand::iterator i = Demand::begin(); i != Demand::end(); ++i)
    demands_per_cluster[i->getCluster()].push_back(&*i);

  // Delete of operationplans of the affected clusters
  // This deletion is not multi-threaded... But on the other hand we need to
  // loop through the operations only once (rather than as many times as there
  // are clusters)
  if (getErasePreviousFirst())
  {
    if (getLogLevel()>0) logger << "Deleting previous plan" << endl;
    for (Operation::iterator e=Operation::begin(); e!=Operation::end(); ++e)
      e->deleteOperationPlans();
  }

  // Solve in parallel threads.
  // When not solving in silent and autocommit mode, we only use a single
  // solver thread.
  // Otherwise we use as many worker threads as processor cores.
  ThreadGroup threads;
  if (getLogLevel()>0 || !getAutocommit())
    threads.setMaxParallel(1);

  // Register all clusters to be solved
  for (int j = 0; j < cl; ++j)
    threads.add(
      SolverMRPdata::runme,
      new SolverMRPdata(this, j, &(demands_per_cluster[j]))
      );

  // Run the planning command threads and wait for them to exit
  threads.execute();

  // @todo Check the resource setups that were broken - needs to be removed
  for (Resource::iterator gres = Resource::begin(); gres != Resource::end(); ++gres)
    if (gres->getSetupMatrix()) gres->updateSetups();
}
Exemplo n.º 9
0
void vl::LoggerT<T>::add_prelude(std::string& out, LogLevel level)
{
    if (!is_set(pimpl_->options, notimestamp))
        safe_sprintf(out, "{0} ", createTimestamp());
    if (!is_set(pimpl_->options, nologgername))
        safe_sprintf(out, "[{0}] ", pimpl_->name);
    if (!is_set(pimpl_->options, nothreadid))
        safe_sprintf(out, "0x{0:x} ", std::this_thread::get_id());
    if (!is_set(pimpl_->options, nologlevel))
        safe_sprintf(out, "<{0}> ", getLogLevel(level));
}
Exemplo n.º 10
0
void LoggerPlugin::openFile()
{
    if (m_bFilter){
        if ((getLogLevel() & L_EVENTS) == 0){
            qApp->removeEventFilter(this);
            m_bFilter = false;
        }
    }else{
        if (getLogLevel() & L_EVENTS){
            qApp->installEventFilter(this);
            m_bFilter = true;
        }
    }
    if (m_file){
        delete m_file;
        m_file = NULL;
    }
    const char *fname = getFile();
    if ((fname == NULL) || (*fname == 0))
        return;
    // This si because sim crashes when a logfile is larger than 100MB ...
    QFileInfo fileInfo(QFile::decodeName(fname));
    if (fileInfo.size() > 1024 * 1024 * 50) {	// 50MB ...
        QString desiredFileName = fileInfo.fileName() + ".old";
#ifdef WIN32
        fileInfo.dir().remove(desiredFileName);
#endif
        if (!fileInfo.dir().rename(fileInfo.fileName(), desiredFileName)) {
            // won't work --> simply delete...
            fileInfo.dir().remove(fileInfo.fileName());
        }
    }
    // now open file
    m_file = new QFile(QFile::decodeName(fname));
    if (!m_file->open(QIODevice::Append | QIODevice::ReadWrite)){
        delete m_file;
        m_file = NULL;
        log(L_WARN, "Can't open %s", fname);
    }
}
Exemplo n.º 11
0
 //! The constructor
 itsEOInterface( eoPop< EOType > * _pop,
                 eoSelectOne<EOType> * _select, 
                 eoQuadOp<EOType> * _cross, float _cross_rate, 
                 eoMonOp<EOType> * _mutate, float _mutate_rate
               ) 
     : itsMetaheuristic(),
       eoPopulation( _pop ), 
       eoSelect( _select ), 
       eoCross( _cross ), eoCrossRate( _cross_rate), 
       eoMutate( _mutate ), eoMutateRate( _mutate_rate )
 {
     clog << "itsEOInterface::itsEOInterface - getLogLevel:" << getLogLevel() << " - logLevel:" /* << logLevel */<< endl;
     clog << "itsEOInterface::itsEOInterface - getLogKeys().size:" << getLogKeys().size() << " - logKeys.size:" /*<< logKeys.size()*/ << endl;
 }
Exemplo n.º 12
0
/**
 * Throw a Java NullPointerException.  Used when input parameters
 * which should not be null are that.
 *
 * @param message   the name of the parameter that is null
 */
void JNIUtil::throwNullPointerException(const char *message)
{
  if (getLogLevel() >= errorLog)
    logMessage("NullPointerException thrown");

  JNIEnv *env = getEnv();
  jclass clazz = env->FindClass("java/lang/NullPointerException");
  if (isJavaExceptionThrown())
    return;

  env->ThrowNew(clazz, message);
  setExceptionThrown();
  env->DeleteLocalRef(clazz);
}
Exemplo n.º 13
0
	CRFileLogger(const char * fname, bool _autoFlush)
		: f(fopen(fname, "wt")), autoClose(true), autoFlush(_autoFlush)
	{
		static unsigned char utf8sign[] = { 0xEF, 0xBB, 0xBF };
		static const char * log_level_names[] = {
			"FATAL",
			"ERROR",
			"WARN",
			"INFO",
			"DEBUG",
			"TRACE",
		};
		fwrite(utf8sign, 3, 1, f);
		info("Started logging. Level=%s", log_level_names[getLogLevel()]);
	}
Exemplo n.º 14
0
void PostgreSQLDatabase::noticeProcessor( void* this_void, const char * message)
{
	PostgreSQLDatabase* this_ = (PostgreSQLDatabase*)this_void;
	std::size_t ii=0;
	for (; message[ii] && message[ii] != ':'; ++ii);
	if (message[ii])
	{
		_Wolframe::log::LogLevel::Level lv = getLogLevel( std::string( message, ii));
		if (lv != log::LogLevel::LOGLEVEL_UNDEFINED)
		{
			_Wolframe::log::Logger( _Wolframe::log::LogBackend::instance() ).Get( lv) << "PostgreSQL database '" << ((this_)?this_->ID():"") << "': " << (message + ii + 1);
			return;
		}
	}
	LOG_ERROR << "Unknown log message type from PostgreSQL database '" << ((this_)?this_->ID():"") << "': " << message;
}
Exemplo n.º 15
0
struct execResult_t execGetReturnCode(const char **aArguments) {
	struct execResult_t execResult;
	char **argcopy = argCopy(aArguments);
	pid_t pid;
	int status;

	memset(&execResult, 0, sizeof(execResult));
	execResult.success = true;

	pid = fork();
	if (pid == -1) {
		perror("fork");
		execResult.success = false;
		return execResult;
	}
	if (pid > 0) {
		char commandLineBuffer[256];
		convertCommandLine(commandLineBuffer, sizeof(commandLineBuffer), aArguments);
		logmsg(LLVL_DEBUG, "Subprocess [PID %d]: Will execute '%s'\n", pid, commandLineBuffer);
	}
	if (pid == 0) {
		/* Child */
		if (getLogLevel() < LLVL_DEBUG) {
			/* Shut up the child if user did not request debug output */
			close(1);
			close(2);
		}
		execvp(aArguments[0], argcopy);
		perror("execvp");
		logmsg(LLVL_ERROR, "Execution of %s in forked child process failed at execvp: %s\n", aArguments[0], strerror(errno));

		/* Exec failed, terminate chExec failed, terminate child process
		 * (parent will catch this as the return code) */
		exit(EXIT_FAILURE);
	}

	if (waitpid(pid, &status, 0) == (pid_t)-1) {
		perror("waitpid");
		execResult.success = false;
		return execResult;
	}

	freeArgCopy(argcopy);
	execResult.returnCode = WEXITSTATUS(status);
	logmsg(LLVL_DEBUG, "Subprocess [PID %d]: %s returned %d\n", pid, aArguments[0], execResult.returnCode);
	return execResult;
}
Exemplo n.º 16
0
void JNIUtil::raiseThrowable(const char *name, const char *message)
{
  if (getLogLevel() >= errorLog)
    {
      JNICriticalSection cs(*g_logMutex);
      g_logStream << "Throwable raised <" << message << ">" << std::endl;
    }

  JNIEnv *env = getEnv();
  jclass clazz = env->FindClass(name);
  if (isJavaExceptionThrown())
    return;

  env->ThrowNew(clazz, message);
  setExceptionThrown();
  env->DeleteLocalRef(clazz);
}
Exemplo n.º 17
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
void xLogger::publishRecord(xLogRecord& record)
{
	synchronizeStart();
	
	if(record.getLevel() <= getLogLevel())
	{
		xIterator* iter = m_handlers.iterator();
		while(iter->hasNext())
		{
			xLogHandler* lh = dynamic_cast<xLogHandler*>(&(iter->next()));
			if(lh != NULL)
				lh->publish(record);
		}	
		delete iter;
	}
	
	synchronizeEnd();
}
Exemplo n.º 18
0
void
JNIUtil::throwNativeException(const char *className, const char *msg,
                              const char *source, int aprErr)
{
  JNIEnv *env = getEnv();
  jclass clazz = env->FindClass(className);

  // Create a local frame for our references
  env->PushLocalFrame(LOCAL_FRAME_SIZE);
  if (JNIUtil::isJavaExceptionThrown())
    return;

  if (getLogLevel() >= exceptionLog)
    {
      JNICriticalSection cs(*g_logMutex);
      g_logStream << "Subversion JavaHL exception thrown, message:<";
      g_logStream << msg << ">";
      if (source)
        g_logStream << " source:<" << source << ">";
      if (aprErr != -1)
        g_logStream << " apr-err:<" << aprErr << ">";
      g_logStream << std::endl;
    }
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  jstring jmessage = makeJString(msg);
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();
  jstring jsource = makeJString(source);
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  jmethodID mid = env->GetMethodID(clazz, "<init>",
                                   "(Ljava/lang/String;Ljava/lang/String;I)V");
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();
  jobject nativeException = env->NewObject(clazz, mid, jmessage, jsource,
                                           static_cast<jint>(aprErr));
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  env->Throw(static_cast<jthrowable>(env->PopLocalFrame(nativeException)));
}
Exemplo n.º 19
0
void HttpServerConfigFacade::reloadConfiguration(std::string const &filePath) {
	rapidxml::file<> xmlFile(filePath.c_str());
	rapidxml::xml_document<> doc;
	doc.parse<0>(xmlFile.data());

	// TODO: reload some other configuration?

	auto httpServer = doc.first_node("HttpServer");
	std::map<std::string, std::string> loggerSettings;
	auto logger = (*httpServer).first_node("Logger");
	if (logger != nullptr) {
		readXmlSettings(logger, loggerSettings);
		if (loggerSettings.empty()) {
			// TDOO: throw an exception?
			return;
		}
		auto level = loggerSettings["Level"];
		RAPID_LOG_TRACE() << "New logging level: " << level;
		rapid::logging::setLogLevel(getLogLevel(level));
	}
}
Exemplo n.º 20
0
void OperatorDelete::solve(const Resource* r, void* v)
{
    if (getLogLevel()>0)
        logger << "Scanning " << r << " for excess" << endl;

    // Loop over all operationplans on the resource
    for (Resource::loadplanlist::const_iterator i = r->getLoadPlans().begin();
            i != r->getLoadPlans().end(); ++i)
    {
        if (i->getEventType() == 1)
            // Add all buffers into which material is produced to the stack
            pushBuffers(static_cast<const LoadPlan*>(&*i)->getOperationPlan(), false);
    }

    // Process all buffers found, and their upstream colleagues
    while(!buffersToScan.empty())
    {
        Buffer* curbuf = buffersToScan.back();
        buffersToScan.pop_back();
        solve(curbuf);
    }
}
Exemplo n.º 21
0
void OperatorDelete::solve(const Demand* d, void* v)
{
    if (getLogLevel()>1)
        logger << "Scanning " << d << " for excess" << endl;

    // Delete all delivery operationplans.
    // Note that an extra loop is used to assure that our iterator doesn't get
    // invalidated during the deletion.
    while (true)
    {
        // Find a candidate operationplan to delete
        OperationPlan *candidate = nullptr;
        const Demand::OperationPlanList& deli = d->getDelivery();
        for (Demand::OperationPlanList::const_iterator i = deli.begin(); i != deli.end(); ++i)
            if (!(*i)->getLocked())
            {
                candidate = *i;
                break;
            }
        if (!candidate) break;

        // Push the buffer on the stack in which the deletion creates excess inventory
        pushBuffers(candidate, true);

        // Delete only the delivery, immediately or through a delete command
        if (cmds)
            cmds->add(new CommandDeleteOperationPlan(candidate));
        else
            delete candidate;
    }

    // Propagate to all upstream buffers
    while(!buffersToScan.empty())
    {
        Buffer* curbuf = buffersToScan.back();
        buffersToScan.pop_back();
        solve(curbuf);
    }
}
Exemplo n.º 22
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
void xLogHandlerFile::publish(xLogRecord& record)
{
	if(record.getLevel() <= getLogLevel())
		m_out->write(getFormatter().format(record));
}
Exemplo n.º 23
0
Arquivo: s3conf.cpp Projeto: 50wu/gpdb
S3Params InitConfig(const string& urlWithOptions) {
#ifdef S3_STANDALONE
    s3ext_segid = 0;
    s3ext_segnum = 1;
#else
    s3ext_segid = GpIdentity.segindex;
    s3ext_segnum = GpIdentity.numsegments;
#endif

    if (s3ext_segid == -1 && s3ext_segnum > 0) {
        s3ext_segid = 0;
        s3ext_segnum = 1;
    }

    string sourceUrl = TruncateOptions(urlWithOptions);
    S3_CHECK_OR_DIE(!sourceUrl.empty(), S3RuntimeError, "URL not found from location string");

    string configPath = GetOptS3(urlWithOptions, "config");
    if (configPath.empty()) {
        S3WARN("The 'config' parameter is not provided, use default value 's3/s3.conf'.");
        configPath = "s3/s3.conf";
    }

    string configSection = GetOptS3(urlWithOptions, "section");
    if (configSection.empty()) {
        configSection = "default";
    }

    // region could be empty
    string urlRegion = GetOptS3(urlWithOptions, "region");

    // read configurations from file
    Config s3Cfg(configPath);

    S3_CHECK_OR_DIE(s3Cfg.Handle() != NULL, S3RuntimeError,
                    "Failed to parse config file '" + configPath + "', or it doesn't exist");

    S3_CHECK_OR_DIE(s3Cfg.SectionExist(configSection), S3ConfigError,
                    "Selected section '" + configSection +
                        "' does not exist, please check your configuration file",
                    configSection);

    bool useHttps = s3Cfg.GetBool(configSection, "encryption", "true");
    bool verifyCert = s3Cfg.GetBool(configSection, "verifycert", "true");

    string version = s3Cfg.Get(configSection, "version", "");

    S3Params params(sourceUrl, useHttps, version, urlRegion);

    string content = s3Cfg.Get(configSection, "loglevel", "WARNING");
    s3ext_loglevel = getLogLevel(content.c_str());

    content = s3Cfg.Get(configSection, "logtype", "INTERNAL");
    s3ext_logtype = getLogType(content.c_str());

    params.setDebugCurl(s3Cfg.GetBool(configSection, "debug_curl", "false"));

    params.setCred(s3Cfg.Get(configSection, "accessid", ""), s3Cfg.Get(configSection, "secret", ""),
                   s3Cfg.Get(configSection, "token", ""));

    s3ext_logserverhost = s3Cfg.Get(configSection, "logserverhost", "127.0.0.1");

    s3ext_logserverport = s3Cfg.SafeScan("logserverport", configSection, 1111, 1, 65535);

    int64_t numOfChunks = s3Cfg.SafeScan("threadnum", configSection, 4, 1, 8);
    params.setNumOfChunks(numOfChunks);

    int64_t chunkSize = s3Cfg.SafeScan("chunksize", configSection, 64 * 1024 * 1024,
                                       8 * 1024 * 1024, 128 * 1024 * 1024);
    params.setChunkSize(chunkSize);

    int64_t lowSpeedLimit = s3Cfg.SafeScan("low_speed_limit", configSection, 10240, 0, INT_MAX);
    params.setLowSpeedLimit(lowSpeedLimit);

    int64_t lowSpeedTime = s3Cfg.SafeScan("low_speed_time", configSection, 60, 0, INT_MAX);
    params.setLowSpeedTime(lowSpeedTime);

    params.setVerifyCert(verifyCert);

    CheckEssentialConfig(params);

    return params;
}
Exemplo n.º 24
0
int main(int argc, char* argv[]) {
    try {

        parseArgs(argc, argv);

        std::vector<std::string*> queries;

        std::string connectStr=qsOptionValues["connectStr"];
        std::string schema=qsOptionValues["schema"];
        std::string queryList=qsOptionValues["query"];
        std::string planList=qsOptionValues["plan"];
        std::string api=qsOptionValues["api"];
        std::string type_str=qsOptionValues["type"];
        std::string logLevel=qsOptionValues["logLevel"];
        std::string testCancel=qsOptionValues["testCancel"];

        Drill::QueryType type;

        if(!validate(type_str, queryList, planList)){
            exit(1);
        }

        Drill::logLevel_t l=getLogLevel(logLevel.c_str());

        std::vector<std::string> queryInputs;
        if(type_str=="sql" ){
            readQueries(queryList, queryInputs);
            type=Drill::SQL;
        }else if(type_str=="physical" ){
            readPlans(planList, queryInputs);
            type=Drill::PHYSICAL;
        }else if(type_str == "logical"){
            readPlans(planList, queryInputs);
            type=Drill::LOGICAL;
        }else{
            readQueries(queryList, queryInputs);
            type=Drill::SQL;
        }

        bTestCancel = !strcmp(testCancel.c_str(), "true")?true:false;

        std::vector<std::string>::iterator queryInpIter;

        std::vector<Drill::RecordIterator*> recordIterators;
        std::vector<Drill::RecordIterator*>::iterator recordIterIter;

        std::vector<Drill::QueryHandle_t*> queryHandles;
        std::vector<Drill::QueryHandle_t*>::iterator queryHandleIter;

        Drill::DrillClient client;
        // To log to file
        //DrillClient::initLogging("/var/log/drill/", l);
        // To log to stderr
        Drill::DrillClient::initLogging(NULL, l);
        Drill::DrillClientConfig::setBufferLimit(2*1024*1024); // 2MB. Allows us to hold at least two record batches.

        if(client.connect(connectStr.c_str(), schema.c_str())!=Drill::CONN_SUCCESS){
            std::cerr<< "Failed to connect with error: "<< client.getError() << " (Using:"<<connectStr<<")"<<std::endl;
            return -1;
        }
        std::cout<< "Connected!\n" << std::endl;

        if(api=="sync"){
            Drill::DrillClientError* err=NULL;
            Drill::status_t ret;
            for(queryInpIter = queryInputs.begin(); queryInpIter != queryInputs.end(); queryInpIter++) {
                Drill::RecordIterator* pRecIter = client.submitQuery(type, *queryInpIter, err);
                if(pRecIter!=NULL){
                    recordIterators.push_back(pRecIter);
                }
            }
            size_t row=0;
            for(recordIterIter = recordIterators.begin(); recordIterIter != recordIterators.end(); recordIterIter++) {
                // get fields.
                row=0;
                Drill::RecordIterator* pRecIter=*recordIterIter;
                Drill::FieldDefPtr fields= pRecIter->getColDefs();
                while((ret=pRecIter->next()), ret==Drill::QRY_SUCCESS || ret==Drill::QRY_SUCCESS_WITH_INFO){
                    fields = pRecIter->getColDefs();
                    row++;
                    if( (ret==Drill::QRY_SUCCESS_WITH_INFO  && pRecIter->hasSchemaChanged() )|| ( row%100==1)){
                        for(size_t i=0; i<fields->size(); i++){
                            std::string name= fields->at(i)->getName();
                            printf("%s\t", name.c_str());
                        }
                        printf("\n");
                    }
                    printf("ROW: %ld\t", row);
                    for(size_t i=0; i<fields->size(); i++){
                        void* pBuf; size_t sz;
                        pRecIter->getCol(i, &pBuf, &sz);
                        print(fields->at(i), pBuf, sz);
                    }
                    printf("\n");
                    if(bTestCancel && row%100==1){
                        pRecIter->cancel();
                        printf("Application canceled the query.\n");
                }
                }
                if(ret!=Drill::QRY_NO_MORE_DATA && ret!=Drill::QRY_CANCEL){
                    std::cerr<< pRecIter->getError() << std::endl;
                }
                client.freeQueryIterator(&pRecIter);
            }
        }else{
            for(queryInpIter = queryInputs.begin(); queryInpIter != queryInputs.end(); queryInpIter++) {
                Drill::QueryHandle_t* qryHandle = new Drill::QueryHandle_t;
                client.submitQuery(type, *queryInpIter, QueryResultsListener, NULL, qryHandle);
                client.registerSchemaChangeListener(qryHandle, SchemaListener);
                queryHandles.push_back(qryHandle);
            }
            client.waitForResults();
            for(queryHandleIter = queryHandles.begin(); queryHandleIter != queryHandles.end(); queryHandleIter++) {
                client.freeQueryResources(*queryHandleIter);
                delete *queryHandleIter;
            }
        }
        client.close();
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
Exemplo n.º 25
0
void WindowProxy::BackgroundTask::operator()()
{
    if (!window)
        return;

    unsigned command;
    while (!((command = sleep()) & Abort)) {
        try {
            if (!window->getWindowPtr()) {
                state = Init;
                continue;
            }

            //
            // Restart
            //
            if (command & Restart) {
                deleteView();
                state = Init;
            }

            // A binding document does not need a view.
            if (window->isBindingDocumentWindow()) {
                state = Done;
                continue;
            }

            //
            // Cascade
            //
            if (!view || (command & Cascade)) {
                state = Cascading;
                recordTime("%*sselector matching begin", window->windowDepth * 2, "");
                if (!view)
                    view = new(std::nothrow) ViewCSSImp(window->getWindowPtr());
                if (view) {
                    view->constructComputedStyles();
                    state = Cascaded;
                } else
                    state = Init;
                recordTime("%*sselector matching end", window->windowDepth * 2, "");
                continue;
            }

            //
            // Layout
            //
            if (command & Layout) {
                state = Layouting;
                view->setSize(window->width, window->height);   // TODO: sync with mainloop
                recordTime("%*sstyle recalculation begin", window->windowDepth * 2, "");
                view->calculateComputedStyles();
                recordTime("%*sstyle recalculation end", window->windowDepth * 2, "");
                recordTime("%*sreflow begin", window->windowDepth * 2, "");
                view->layOut();
                recordTime("%*sreflow end", window->windowDepth * 2, "");

                // Even though every view flag should have been cleared now,
                // check them here and clear all of them after dumping the tree.
                if (view->gatherFlags() & ~Box::NEED_REPAINT) {
                    std::cerr << "warning: reflow flags are not fully cleared:\n";
                    int level = getLogLevel();
                    if (level < 3)
                        setLogLevel(3);
                    view->dump();
                    setLogLevel(level);
                    view->clearFlags();
                }

                view->setFlags(Box::NEED_REPAINT);
            }

            state = Done;
        } catch (const std::exception& e) {
            std::cerr << "WindowProxy::BackgroundTask: " << e.what() << "\n";
            throw;
            // TODO: Recover from exceptions
        }
    }
}
Exemplo n.º 26
0
void setLogLevel(LogLevel logLevel)
    {
    getLogLevel() = logLevel;
    }
Exemplo n.º 27
0
Ufora::ScopedLoggingHandles& scopedLoggingHandlesSingleton()
    {
    static Ufora::ScopedLoggingHandles result(&getLogLevel());

    return result;
    }
Exemplo n.º 28
0
int main(int argc, char* argv[]) {
    try {

        parseArgs(argc, argv);

        std::vector<std::string*> queries;

        std::string connectStr=qsOptionValues["connectStr"];
        std::string schema=qsOptionValues["schema"];
        std::string queryList=qsOptionValues["query"];
        std::string planList=qsOptionValues["plan"];
        std::string api=qsOptionValues["api"];
        std::string type_str=qsOptionValues["type"];
        std::string logLevel=qsOptionValues["logLevel"];
        std::string testCancel=qsOptionValues["testCancel"];
        std::string syncSend=qsOptionValues["syncSend"];
        std::string hshakeTimeout=qsOptionValues["hshakeTimeout"];
        std::string queryTimeout=qsOptionValues["queryTimeout"];
        std::string heartbeatFrequency=qsOptionValues["heartbeatFrequency"];
        std::string user=qsOptionValues["user"];
        std::string password=qsOptionValues["password"];
        std::string saslPluginPath=qsOptionValues["saslPluginPath"];
        std::string sasl_encrypt=qsOptionValues["sasl_encrypt"];
        std::string serviceHost=qsOptionValues["service_host"];
        std::string serviceName=qsOptionValues["service_name"];
        std::string auth=qsOptionValues["auth"];
        std::string enableSSL=qsOptionValues["enableSSL"];
        std::string tlsProtocol=qsOptionValues["TLSProtocol"];
        std::string certFilePath=qsOptionValues["certFilePath"];
        std::string disableHostnameVerification=qsOptionValues["disableHostnameVerification"];
        std::string disableCertVerification=qsOptionValues["disableCertVerification"];
        std::string useSystemTrustStore = qsOptionValues["useSystemTrustStore"];

        Drill::QueryType type;

        if(!validate(type_str, queryList, planList)){
            exit(1);
        }

        Drill::logLevel_t l=getLogLevel(logLevel.c_str());

        std::vector<std::string> queryInputs;
        if(type_str=="sql" ){
            readQueries(queryList, queryInputs);
            type=Drill::SQL;
        }else if(type_str=="physical" ){
            readPlans(planList, queryInputs);
            type=Drill::PHYSICAL;
        }else if(type_str == "logical"){
            readPlans(planList, queryInputs);
            type=Drill::LOGICAL;
        }else{
            readQueries(queryList, queryInputs);
            type=Drill::SQL;
        }

        bTestCancel = !strcmp(testCancel.c_str(), "true")?true:false;
        bSyncSend = !strcmp(syncSend.c_str(), "true")?true:false;

        std::vector<std::string>::iterator queryInpIter;

        std::vector<Drill::RecordIterator*> recordIterators;
        std::vector<Drill::RecordIterator*>::iterator recordIterIter;

        std::vector<Drill::QueryHandle_t> queryHandles;
        std::vector<Drill::QueryHandle_t>::iterator queryHandleIter;

        Drill::DrillClient client;
#if defined _WIN32 || defined _WIN64
        TCHAR tempPath[MAX_PATH];
        GetTempPath(MAX_PATH, tempPath);
		char logpathPrefix[MAX_PATH + 128];
		strcpy(logpathPrefix,tempPath);
		strcat(logpathPrefix, "\\drillclient");
#else
		const char* logpathPrefix = "/var/log/drill/drillclient";
#endif
		// To log to file
        Drill::DrillClient::initLogging(logpathPrefix, l);
        // To log to stderr
        //Drill::DrillClient::initLogging(NULL, l);

        int nQueries=queryInputs.size();
        Drill::DrillClientConfig::setBufferLimit(nQueries*2*1024*1024); // 2MB per query. The size of a record batch may vary, but is unlikely to exceed the 256 MB which is the default. 

        if(!hshakeTimeout.empty()){
            Drill::DrillClientConfig::setHandshakeTimeout(atoi(hshakeTimeout.c_str()));
        }
        if (!queryTimeout.empty()){
            Drill::DrillClientConfig::setQueryTimeout(atoi(queryTimeout.c_str()));
        }
        if(!heartbeatFrequency.empty()) {
            Drill::DrillClientConfig::setHeartbeatFrequency(atoi(heartbeatFrequency.c_str()));
        }
        if (!saslPluginPath.empty()){
            Drill::DrillClientConfig::setSaslPluginPath(saslPluginPath.c_str());
        }

        Drill::DrillUserProperties props;
        if(schema.length()>0){
            props.setProperty(USERPROP_SCHEMA, schema);
        }
        if(user.length()>0){
            props.setProperty(USERPROP_USERNAME, user);
        }
        if(password.length()>0){
            props.setProperty(USERPROP_PASSWORD, password);
        }
        if(sasl_encrypt.length()>0){
            props.setProperty(USERPROP_SASL_ENCRYPT, sasl_encrypt);
        }
        if(serviceHost.length()>0){
            props.setProperty(USERPROP_SERVICE_HOST, serviceHost);
        }
        if(serviceName.length()>0){
            props.setProperty(USERPROP_SERVICE_NAME, serviceName);
        }
        if(auth.length()>0){
            props.setProperty(USERPROP_AUTH_MECHANISM, auth);
        }
        if(enableSSL.length()>0){
            props.setProperty(USERPROP_USESSL, enableSSL);
			if (enableSSL == "true" && certFilePath.length() <= 0 && useSystemTrustStore.length() <= 0){
                std::cerr<< "SSL is enabled but no certificate or truststore provided. " << std::endl;
                return -1;
            }
            props.setProperty(USERPROP_TLSPROTOCOL, tlsProtocol);
            props.setProperty(USERPROP_CERTFILEPATH, certFilePath);
            props.setProperty(USERPROP_DISABLE_HOSTVERIFICATION, disableHostnameVerification);
            props.setProperty(USERPROP_DISABLE_CERTVERIFICATION, disableCertVerification);
			if (useSystemTrustStore.length() > 0){
				props.setProperty(USERPROP_USESYSTEMTRUSTSTORE, useSystemTrustStore);
			}
        }

        if(client.connect(connectStr.c_str(), &props)!=Drill::CONN_SUCCESS){
            std::cerr<< "Failed to connect with error: "<< client.getError() << " (Using:"<<connectStr<<")"<<std::endl;
            return -1;
        }
        std::cout<< "Connected!\n" << std::endl;
        if(api=="meta") {
        	Drill::Metadata* metadata = client.getMetadata();
        	if (metadata) {
        		std::cout << "Connector:" << std::endl;
        		std::cout << "\tname:" << metadata->getConnectorName() << std::endl;
        		std::cout << "\tversion:" << metadata->getConnectorVersion() << std::endl;
        		std::cout << std::endl;
        		std::cout << "Server:" << std::endl;
        		std::cout << "\tname:" << metadata->getServerName() << std::endl;
        		std::cout << "\tversion:" << metadata->getServerVersion() << std::endl;
        		std::cout << std::endl;
        		std::cout << "Metadata:" << std::endl;
        		std::cout << "\tall tables are selectable: " << metadata->areAllTableSelectable() << std::endl;
        		std::cout << "\tcatalog separator: " << metadata->getCatalogSeparator() << std::endl;
        		std::cout << "\tcatalog term: " << metadata->getCatalogTerm() << std::endl;
        		std::cout << "\tCOLLATE support: " << metadata->getCollateSupport() << std::endl;
        		std::cout << "\tcorrelation names: " << metadata->getCorrelationNames() << std::endl;
        		std::cout << "\tdate time functions: " << boost::algorithm::join(metadata->getDateTimeFunctions(), ", ") << std::endl;
        		std::cout << "\tdate time literals support: " << metadata->getDateTimeLiteralsSupport() << std::endl;
        		std::cout << "\tGROUP BY support: " << metadata->getGroupBySupport() << std::endl;
        		std::cout << "\tidentifier case: " << metadata->getIdentifierCase() << std::endl;
        		std::cout << "\tidentifier quote string: " << metadata->getIdentifierQuoteString() << std::endl;
        		std::cout << "\tmax binary literal length: " << metadata->getMaxBinaryLiteralLength() << std::endl;
        		std::cout << "\tmax catalog name length: " << metadata->getMaxCatalogNameLength() << std::endl;
        		std::cout << "\tmax char literal length: " << metadata->getMaxCharLiteralLength() << std::endl;
        		std::cout << "\tmax column name length: " << metadata->getMaxColumnNameLength() << std::endl;
        		std::cout << "\tmax columns in GROUP BY: " << metadata->getMaxColumnsInGroupBy() << std::endl;
        		std::cout << "\tmax columns in ORDER BY: " << metadata->getMaxColumnsInOrderBy() << std::endl;
        		std::cout << "\tmax columns in SELECT: " << metadata->getMaxColumnsInSelect() << std::endl;
        		std::cout << "\tmax cursor name length: " << metadata->getMaxCursorNameLength() << std::endl;
        		std::cout << "\tmax logical lob size: " << metadata->getMaxLogicalLobSize() << std::endl;
        		std::cout << "\tmax row size: " << metadata->getMaxRowSize() << std::endl;
        		std::cout << "\tmax schema name length: " << metadata->getMaxSchemaNameLength() << std::endl;
        		std::cout << "\tmax statement length: " << metadata->getMaxStatementLength() << std::endl;
        		std::cout << "\tmax statements: " << metadata->getMaxStatements() << std::endl;
        		std::cout << "\tmax table name length: " << metadata->getMaxTableNameLength() << std::endl;
        		std::cout << "\tmax tables in SELECT: " << metadata->getMaxTablesInSelect() << std::endl;
        		std::cout << "\tmax user name length: " << metadata->getMaxUserNameLength() << std::endl;
        		std::cout << "\tNULL collation: " << metadata->getNullCollation() << std::endl;
        		std::cout << "\tnumeric functions: " << boost::algorithm::join(metadata->getNumericFunctions(), ", ") << std::endl;
        		std::cout << "\tOUTER JOIN support: " << metadata->getOuterJoinSupport() << std::endl;
        		std::cout << "\tquoted identifier case: " << metadata->getQuotedIdentifierCase() << std::endl;
        		std::cout << "\tSQL keywords: " << boost::algorithm::join(metadata->getSQLKeywords(), ",") << std::endl;
        		std::cout << "\tschema term: " << metadata->getSchemaTerm() << std::endl;
        		std::cout << "\tsearch escape string: " << metadata->getSearchEscapeString() << std::endl;
        		std::cout << "\tspecial characters: " << metadata->getSpecialCharacters() << std::endl;
        		std::cout << "\tstring functions: " << boost::algorithm::join(metadata->getStringFunctions(), ",") << std::endl;
        		std::cout << "\tsub query support: " << metadata->getSubQuerySupport() << std::endl;
        		std::cout << "\tsystem functions: " << boost::algorithm::join(metadata->getSystemFunctions(), ",") << std::endl;
        		std::cout << "\ttable term: " << metadata->getTableTerm() << std::endl;
        		std::cout << "\tUNION support: " << metadata->getUnionSupport() << std::endl;
        		std::cout << "\tBLOB included in max row size: " << metadata->isBlobIncludedInMaxRowSize() << std::endl;
        		std::cout << "\tcatalog at start: " << metadata->isCatalogAtStart() << std::endl;
        		std::cout << "\tcolumn aliasing supported: " << metadata->isColumnAliasingSupported() << std::endl;
        		std::cout << "\tLIKE escape clause supported: " << metadata->isLikeEscapeClauseSupported() << std::endl;
        		std::cout << "\tNULL plus non NULL equals to NULL: " << metadata->isNullPlusNonNullNull() << std::endl;
        		std::cout << "\tread-only: " << metadata->isReadOnly() << std::endl;
        		std::cout << "\tSELECT FOR UPDATE supported: " << metadata->isSelectForUpdateSupported() << std::endl;
        		std::cout << "\ttransaction supported: " << metadata->isTransactionSupported() << std::endl;
        		std::cout << "\tunrelated columns in ORDER BY supported: " << metadata->isUnrelatedColumnsInOrderBySupported() << std::endl;

        		client.freeMetadata(&metadata);
        	} else {
        		std::cerr << "Cannot get metadata:" << client.getError() << std::endl;
        	}
        } else if(api=="sync"){
            Drill::DrillClientError* err=NULL;
            Drill::status_t ret;
            int nQueries=0;
            for(queryInpIter = queryInputs.begin(); queryInpIter != queryInputs.end(); queryInpIter++) {
                Drill::RecordIterator* pRecIter = client.submitQuery(type, *queryInpIter, err);
                if(pRecIter!=NULL){
                    recordIterators.push_back(pRecIter);
                    nQueries++;
                }
            }
            Drill::DrillClientConfig::setBufferLimit(nQueries*2*1024*1024); // 2MB per query. Allows us to hold at least two record batches.
            size_t row=0;
            for(recordIterIter = recordIterators.begin(); recordIterIter != recordIterators.end(); recordIterIter++) {
                // get fields.
                row=0;
                Drill::RecordIterator* pRecIter=*recordIterIter;
                Drill::FieldDefPtr fields= pRecIter->getColDefs();
                while((ret=pRecIter->next()), (ret==Drill::QRY_SUCCESS || ret==Drill::QRY_SUCCESS_WITH_INFO) && !pRecIter->hasError()){
                    fields = pRecIter->getColDefs();
                    row++;
                    if( (ret==Drill::QRY_SUCCESS_WITH_INFO  && pRecIter->hasSchemaChanged() )|| ( row%100==1)){
                        for(size_t i=0; i<fields->size(); i++){
                            std::string name= fields->at(i)->getName();
                            printf("%s\t", name.c_str());
                        }
                        printf("\n");
                    }
                    printf("ROW: %ld\t", row);
                    for(size_t i=0; i<fields->size(); i++){
                        void* pBuf; size_t sz;
                        pRecIter->getCol(i, &pBuf, &sz);
                        print(fields->at(i), pBuf, sz);
                    }
                    printf("\n");
                    if(bTestCancel && row%100==1){
                        pRecIter->cancel();
                        printf("Application cancelled the query.\n");
                    }
                }
                if(ret!=Drill::QRY_NO_MORE_DATA && ret!=Drill::QRY_CANCEL){
                    std::cerr<< pRecIter->getError() << std::endl;
                }
                client.freeQueryIterator(&pRecIter);
            }
            client.waitForResults();
        }else{
            if(bSyncSend){
                for(queryInpIter = queryInputs.begin(); queryInpIter != queryInputs.end(); queryInpIter++) {
                    Drill::QueryHandle_t qryHandle;
                    client.submitQuery(type, *queryInpIter, QueryResultsListener, NULL, &qryHandle);
                    client.registerSchemaChangeListener(&qryHandle, SchemaListener);
                    
                     if(bTestCancel) {
                        // Send cancellation request after 5seconds
                        boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
                        std::cout<< "\n Cancelling query: " << *queryInpIter << "\n" << std::endl;
                        client.cancelQuery(qryHandle);
                    } else {
                        client.waitForResults();
                    }

                    client.freeQueryResources(&qryHandle);
                }

            }else{
                for(queryInpIter = queryInputs.begin(); queryInpIter != queryInputs.end(); queryInpIter++) {
                    Drill::QueryHandle_t qryHandle;
                    client.submitQuery(type, *queryInpIter, QueryResultsListener, NULL, &qryHandle);
                    client.registerSchemaChangeListener(&qryHandle, SchemaListener);
                    queryHandles.push_back(qryHandle);
                }
                client.waitForResults();
                for(queryHandleIter = queryHandles.begin(); queryHandleIter != queryHandles.end(); queryHandleIter++) {
                    client.freeQueryResources(&*queryHandleIter);
                }
            }
        }
        client.close();
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
Exemplo n.º 29
0
void HttpServerConfigFacade::loadConfiguration(std::string const &filePath) {
	rapidxml::file<> xmlFile(filePath.c_str());
	rapidxml::xml_document<> doc;
	doc.parse<0>(xmlFile.data());

	auto httpServer = doc.first_node("HttpServer");

	std::map<std::string, std::string> tcpSettings;
	auto server = (*httpServer).first_node("Server");
	readXmlSettings(server, tcpSettings);
	// Setting TCP config
	{
		listenPort_ = std::strtoul(tcpSettings["Port"].c_str(), nullptr, 10);
		initialUserConnection_ = std::strtoul(tcpSettings["InitialUserConnection"].c_str(), nullptr, 10);
		maxUserConnection_ = std::strtoul(tcpSettings["MaxUserConnection"].c_str(), nullptr, 10);
		bufferSize_ = SIZE_128KB;
		numaNode_ = std::strtoul(tcpSettings["NumaNode"].c_str(), nullptr, 10);
	}

	std::map<std::string, std::string> httpSettings;
	auto http = (*httpServer).first_node("Http");
	readXmlSettings(http, httpSettings);
	// Setting HTTP config
	{
		host_ = httpSettings["Host"];
		serverName_ = httpSettings["ServerName"];
		enableSSLProto_ = httpSettings["EnableSSL"] == "true" ? true : false;
		enableHttp2Proto_ = httpSettings["EnableHTTP2"] == "true" ? true : false;
		tempFilePath_ = httpSettings["TempFilePath"];
		rootPath_ = httpSettings["RootPath"];
		indexFileName_ = httpSettings["IndexFileName"];
	}

	std::map<std::string, std::string> sslSettings;
	auto ssl = (*httpServer).first_node("SSL");
	if (ssl != nullptr) {
		readXmlSettings(ssl, sslSettings);
		// Setting SSL config
		{
			certificateFilePath_ = sslSettings["CertificateFilePath"];
			privateKeyFilePath_ = sslSettings["PrivateKeyFilePath"];
		}
	}

	std::map<std::string, std::string> loggerSettings;
	auto logger = (*httpServer).first_node("Logger");
	if (logger != nullptr) {
		readXmlSettings(logger, loggerSettings);
		if (loggerSettings.empty()) {
			// TDOO: throw an exception?
			return;
		}
		rapid::logging::startLogging(getLogLevel(loggerSettings["Level"]));
		std::vector<std::shared_ptr<rapid::logging::LogAppender>> appenders;
		std::map<std::string, rapidxml::xml_node<char> *> settings;
		readAppenderSettring(logger, settings);
		if (settings.empty()) {
			// TDOO: throw an exception?
			return;
		}
		createAppenderFromSetting(settings, appenders);
	} else {
		// TDOO: throw an exception?
		return;
	}

	namespace FS = std::tr2::sys;
	FS::path watchFilePath(filePath);

	pFileWatcher_ = std::make_unique<rapid::platform::FileSystemWatcher>(watchFilePath.parent_path());
	pFileWatchTimer_ = rapid::details::Timer::createTimer();

	pFileWatchTimer_->start([this, filePath]() {
		if (!pFileWatcher_->getChangedFile().empty()) {
			RAPID_LOG_TRACE() << "File configuration changed!";
			try {
				reloadConfiguration(filePath);
			} catch (std::exception const &e) {
				RAPID_LOG_FATAL() << e.what();
			}
		}
	}, 500);
}
Exemplo n.º 30
0
void JNIUtil::wrappedHandleSVNError(svn_error_t *err)
{
  std::string msg;
  assembleErrorMessage(svn_error_purge_tracing(err), 0, APR_SUCCESS, msg);
  const char *source = NULL;
#ifdef SVN_DEBUG
#ifndef SVN_ERR__TRACING
  if (err->file)
    {
      std::ostringstream buf;
      buf << err->file;
      if (err->line > 0)
        buf << ':' << err->line;
      source = buf.str().c_str();
    }
#endif
#endif

  // Much of the following is stolen from throwNativeException().  As much as
  // we'd like to call that function, we need to do some manual stack
  // unrolling, so it isn't feasible.

  JNIEnv *env = getEnv();

  // Create a local frame for our references
  env->PushLocalFrame(LOCAL_FRAME_SIZE);
  if (JNIUtil::isJavaExceptionThrown())
    return;

  jclass clazz = env->FindClass(JAVA_PACKAGE "/ClientException");
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  if (getLogLevel() >= exceptionLog)
    {
      JNICriticalSection cs(*g_logMutex);
      g_logStream << "Subversion JavaHL exception thrown, message:<";
      g_logStream << msg << ">";
      if (source)
        g_logStream << " source:<" << source << ">";
      if (err->apr_err != -1)
        g_logStream << " apr-err:<" << err->apr_err << ">";
      g_logStream << std::endl;
    }
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  jstring jmessage = makeJString(msg.c_str());
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();
  jstring jsource = makeJString(source);
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  jmethodID mid = env->GetMethodID(clazz, "<init>",
                                   "(Ljava/lang/String;Ljava/lang/String;I)V");
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();
  jobject nativeException = env->NewObject(clazz, mid, jmessage, jsource,
                                           static_cast<jint>(err->apr_err));
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

#ifdef SVN_ERR__TRACING
  // Add all the C error stack trace information to the Java Exception

  // Get the standard stack trace, and vectorize it using the Array class.
  static jmethodID mid_gst = 0;
  if (mid_gst == 0)
    {
      mid_gst = env->GetMethodID(clazz, "getStackTrace",
                                 "()[Ljava/lang/StackTraceElement;");
      if (isJavaExceptionThrown())
        POP_AND_RETURN_NOTHING();
    }
  Array stackTraceArray((jobjectArray) env->CallObjectMethod(nativeException,
                                                             mid_gst));
  std::vector<jobject> oldStackTrace = stackTraceArray.vector();

  // Build the new stack trace elements from the chained errors.
  std::vector<jobject> newStackTrace;
  putErrorsInTrace(err, newStackTrace);

  // Join the new elements with the old ones
  for (std::vector<jobject>::const_iterator it = oldStackTrace.begin();
            it < oldStackTrace.end(); ++it)
    {
      newStackTrace.push_back(*it);
    }

  jclass stClazz = env->FindClass("java/lang/StackTraceElement");
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  const jsize stSize = static_cast<jsize>(newStackTrace.size());
  if (stSize != newStackTrace.size())
    {
      env->ThrowNew(env->FindClass("java.lang.ArithmeticException"),
                    "Overflow converting C size_t to JNI jsize");
      POP_AND_RETURN_NOTHING();
    }
  jobjectArray jStackTrace = env->NewObjectArray(stSize, stClazz, NULL);
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();

  int i = 0;
  for (std::vector<jobject>::const_iterator it = newStackTrace.begin();
       it < newStackTrace.end(); ++it)
    {
      env->SetObjectArrayElement(jStackTrace, i, *it);
      ++i;
    }

  // And put the entire trace back into the exception
  static jmethodID mid_sst = 0;
  if (mid_sst == 0)
    {
      mid_sst = env->GetMethodID(clazz, "setStackTrace",
                                 "([Ljava/lang/StackTraceElement;)V");
      if (isJavaExceptionThrown())
        POP_AND_RETURN_NOTHING();
    }
  env->CallVoidMethod(nativeException, mid_sst, jStackTrace);
  if (isJavaExceptionThrown())
    POP_AND_RETURN_NOTHING();
#endif

  env->Throw(static_cast<jthrowable>(env->PopLocalFrame(nativeException)));
}