Esempio n. 1
0
/*
 * Makes cache_queue_policy_ behave like FIFO policy - we don't do anything,
 * when the cache element is updated. So it always stays in its initial
 * position in the queue - that is exactly the FIFO functionality.
 */
static void
cache_fifo_policy_update_item(struct cache_policy_ *policy,
	struct cache_policy_item_ *item)
{

	TRACE_IN(cache_fifo_policy_update_item);
	/* policy and item arguments are ignored */
	TRACE_OUT(cache_fifo_policy_update_item);
}
Esempio n. 2
0
void PythonHostEnvironment::getByteBufferPtr(HostRef* obj, char** outBuffer, long& outSize)
{
	TRACE_IN("PythonHostEnvironment::getByteBufferPtr");
	PyObject* objRef = UNWRAP(obj);
	Py_ssize_t tempSize = 0;
	JPyObject::AsPtrAndSize(objRef, outBuffer, &tempSize);
	outSize = (long)tempSize;
	TRACE_OUT;
}
Esempio n. 3
0
/*
 * The default query_destroy function
 */
static void
on_query_destroy(struct query_state *qstate)
{

	TRACE_IN(on_query_destroy);
	finalize_comm_element(&qstate->response);
	finalize_comm_element(&qstate->request);
	TRACE_OUT(on_query_destroy);
}
Esempio n. 4
0
static void *
passwd_mp_init_func(void)
{
	TRACE_IN(passwd_mp_init_func);
	setpwent();
	TRACE_OUT(passwd_mp_init_func);

	return (NULL);
}
Esempio n. 5
0
static struct cache_policy_item_ *
cache_queue_policy_get_first_item(struct cache_policy_ *policy)
{
	struct cache_queue_policy_ *queue_policy;

	TRACE_IN(cache_queue_policy_get_first_item);
	queue_policy = (struct cache_queue_policy_ *)policy;
	TRACE_OUT(cache_queue_policy_get_first_item);
	return ((struct cache_policy_item_ *)TAILQ_FIRST(&queue_policy->head));
}
Esempio n. 6
0
void
destroy_cache_lru_policy(struct cache_policy_ *policy)
{
	struct cache_queue_policy_	*queue_policy;

	TRACE_IN(destroy_cache_lru_policy);
	queue_policy = (struct cache_queue_policy_ *)policy;
	destroy_cache_queue_policy(queue_policy);
	TRACE_OUT(destroy_cache_lru_policy);
}
Esempio n. 7
0
/*
 * The vast majority of the functions below corresponds to the particular
 * keywords in the configuration file.
 */
static void
enable_cache(struct configuration *config, const char *entry_name, int flag)
{
	struct configuration_entry	*entry;

	TRACE_IN(enable_cache);
	entry = find_create_entry(config, entry_name);
	entry->enabled = flag;
	TRACE_OUT(enable_cache);
}
Esempio n. 8
0
jobject JPJavaEnv::NewDirectByteBuffer(void* address, jlong capacity)
{
	TRACE_IN("JPJavaEnv::NewDirectByteBuffer");
	JNIEnv* env = getJNIEnv(); 
    jobject res = env->functions->NewDirectByteBuffer(env, address, capacity);
    JAVA_CHECK("NewDirectByteBuffer");
	TRACE1((long)res);
    return res;	
	TRACE_OUT;
}
Esempio n. 9
0
PyObject* JPypeJavaArray::setArraySlice(PyObject* self, PyObject* arg)
{
	TRACE_IN("JPypeJavaArray::setArraySlice")
	PyObject* arrayObject;
	int lo = -1;
	int hi = -1;
	PyObject* sequence;
	try {
		JPyArg::parseTuple(arg, "O!iiO", &PyCapsule_Type, &arrayObject, &lo, &hi, &sequence);
		JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject);

		int length = a->getLength();
		if(length == 0)
			Py_RETURN_NONE;

		if (lo < 0) lo = length + lo;
		if (lo < 0) lo = 0;
		else if (lo > length) lo = length;
		if (hi < 0) hi = length + hi;
		if (hi < 0) hi = 0;
		else if (hi > length) hi = length;
		if (lo > hi) lo = hi;

		const JPTypeName& componentName = a->getType()->getObjectType().getComponentName();
		const string& name = componentName.getNativeName();

		if(is_primitive(name[0]))
		{
			// for primitive types, we have fast setters available
			a->setRange(lo, hi, sequence);
		}
		else
		{
			// slow wrapped access for non primitive types
			vector<HostRef*> values;
			values.reserve(hi - lo);
			JPCleaner cleaner;
			for (Py_ssize_t i = 0; i < hi - lo; i++)
			{
				HostRef* v = new HostRef(JPySequence::getItem(sequence, i), false);
				values.push_back(v);
				cleaner.add(v);
			}

			a->setRange(lo, hi, values);
		}

		Py_RETURN_NONE;
	}
	PY_STANDARD_CATCH

	return NULL;
	TRACE_OUT
}
Esempio n. 10
0
vector<HostRef*> JPArray::getRange(int start, int stop)
{
	TRACE_IN("JPArray::getRange");
	JPType* compType = m_Class->getComponentType();
	TRACE2("Component type", compType->getName().getSimpleName());
	
	vector<HostRef*> res = compType->getArrayRange(m_Object, start, stop-start);
	
	return res;
	TRACE_OUT;
}	
Esempio n. 11
0
JPTypeName getType(jobject fld)
{
	TRACE_IN("getType");

	JPCleaner cleaner;
	jclass c = (jclass)JPEnv::getJava()->CallObjectMethod(fld, getTypeID);
	cleaner.addLocal(c);

	return getName(c);
	TRACE_OUT;
}
Esempio n. 12
0
void JPObjectType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) 
{
	TRACE_IN("JPObjectType::setStaticValue");
	JPCleaner cleaner;

	jobject val = convertToJava(obj).l;
	cleaner.addLocal(val);

	JPEnv::getJava()->SetStaticObjectField(c, fid, val);
	TRACE_OUT;
}
Esempio n. 13
0
static struct cache_policy_item_ *
cache_queue_policy_get_last_item(struct cache_policy_ *policy)
{
	struct cache_queue_policy_ *queue_policy;

	TRACE_IN(cache_queue_policy_get_last_item);
	queue_policy = (struct cache_queue_policy_ *)policy;
	TRACE_OUT(cache_queue_policy_get_last_item);
	return ((struct cache_policy_item_ *)TAILQ_LAST(&queue_policy->head,
		cache_queue_policy_head_));
}
Esempio n. 14
0
HostRef* JPField::getStaticAttribute()
{
    TRACE_IN("JPField::getStaticAttribute");
    JPType* type = JPTypeManager::getType(m_Type);
    JPCleaner cleaner;
    jclass claz = m_Class->getClass();
    cleaner.addLocal(claz);


    return type->getStaticValue(claz, m_FieldID, m_Type);
    TRACE_OUT;
}
Esempio n. 15
0
void JPEnv::registerRef(HostRef* ref, HostRef* targetRef)
{
	TRACE_IN("JPEnv::registerRef");
	JPObject* objRef = s_Host->asObject(ref);
	JPCleaner cleaner;
	TRACE1("A");
	jobject srcObject = objRef->getObject();
	cleaner.addLocal(srcObject);
	JPJni::registerRef(s_Java->getReferenceQueue(), srcObject, (jlong)targetRef->copy());
	TRACE_OUT;
	TRACE1("B");
}
Esempio n. 16
0
void PyJPBoundMethod::__dealloc__(PyObject* o)
{
	TRACE_IN("PyJPBoundMethod::__dealloc__");
	PyJPBoundMethod* self = (PyJPBoundMethod*)o;

	Py_DECREF(self->m_Instance);
	Py_DECREF(self->m_Method);

	Py_TYPE(self)->tp_free(o);
	TRACE1("Method freed");
	TRACE_OUT;
}
Esempio n. 17
0
void JPJavaEnv::load(const string& path)
{
	TRACE_IN("JPJavaEnv::load");
	
	// WIN32
	GetAdapter()->loadLibrary((char*)path.c_str());
	CreateJVM_Method = (jint (JNICALL *)(struct JavaVM_ ** ,void ** ,void *))GetAdapter()->getSymbol("JNI_CreateJavaVM");
	GetCreatedJVMs_Method = (jint (JNICALL *)(struct JavaVM_ ** , jsize, jsize*))GetAdapter()->getSymbol("JNI_GetCreatedJavaVMs");
	// No idea why I can't find this symbol .... no matter, it does not work anyway.
	//JNI_DestroyJavaVM = (jint (__stdcall *)(struct JavaVM_ *))GetAdapter()->getSymbol("DestroyJavaVM");
TRACE_OUT;
}
Esempio n. 18
0
struct cache_policy_ *
init_cache_lru_policy(void)
{
	struct cache_queue_policy_ *retval;

	TRACE_IN(init_cache_lru_policy);
	retval = init_cache_queue_policy();
	retval->parent_data.update_item_func = cache_lru_policy_update_item;

	TRACE_OUT(init_cache_lru_policy);
	return ((struct cache_policy_ *)retval);
}
Esempio n. 19
0
PyObject* JPypeModule::startup(PyObject* obj, PyObject* args)  
{  
	TRACE_IN("startup");
	try {
		PyObject* vmOpt;
		PyObject* vmPath;
		char ignoreUnrecognized = true;

		JPyArg::parseTuple(args, "OO!b|", &vmPath, &PyTuple_Type, &vmOpt, &ignoreUnrecognized);

		if (! (JPyString::check(vmPath)))
		{
			RAISE(JPypeException, "First paramter must be a string or unicode");
		}

		string cVmPath = JPyString::asString(vmPath);

		StringVector args;

		for (int i = 0; i < JPyObject::length(vmOpt); i++)
		{
			PyObject* obj = JPySequence::getItem(vmOpt, i);

			if (JPyString::check(obj))
			{
				// TODO support unicode
				string v = JPyString::asString(obj);	

				args.push_back(v);
			}
			else if (JPySequence::check(obj))
			{
				//String name = arg[0];
				//Callable value = arg[1];

				// TODO complete this for the hooks ....
			}
			else {
				RAISE(JPypeException, "VM Arguments must be string or tuple");
			}
		}

		JPEnv::loadJVM(cVmPath, ignoreUnrecognized, args);

		Py_INCREF(Py_None);
		return Py_None;
	}
	PY_STANDARD_CATCH

	return NULL;
	TRACE_OUT;
}
Esempio n. 20
0
static void
cache_queue_policy_add_item(struct cache_policy_ *policy,
	struct cache_policy_item_ *item)
{
	struct cache_queue_policy_ *queue_policy;
	struct cache_queue_policy_item_ *queue_item;

	TRACE_IN(cache_queue_policy_add_item);
	queue_policy = (struct cache_queue_policy_ *)policy;
	queue_item = (struct cache_queue_policy_item_ *)item;
	TAILQ_INSERT_TAIL(&queue_policy->head, queue_item, entries);
	TRACE_OUT(cache_queue_policy_add_item);
}
Esempio n. 21
0
/*
 * All cache_queue_policy_XXX functions below will be used to fill
 * the cache_queue_policy structure. They implement the most functionality of
 * LRU and FIFO policies. LRU and FIFO policies are actually the
 * cache_queue_policy_ with cache_update_item function changed.
 */
static struct cache_policy_item_ *
cache_queue_policy_create_item(void)
{
	struct cache_queue_policy_item_ *retval;

	TRACE_IN(cache_queue_policy_create_item);
	retval = calloc(1,
		sizeof(*retval));
	assert(retval != NULL);

	TRACE_OUT(cache_queue_policy_create_item);
	return ((struct cache_policy_item_ *)retval);
}
Esempio n. 22
0
static void
cache_queue_policy_remove_item(struct cache_policy_ *policy,
	struct cache_policy_item_ *item)
{
	struct cache_queue_policy_ *queue_policy;
	struct cache_queue_policy_item_	*queue_item;

	TRACE_IN(cache_queue_policy_remove_item);
	queue_policy = (struct cache_queue_policy_ *)policy;
	queue_item = (struct cache_queue_policy_item_ *)item;
	TAILQ_REMOVE(&queue_policy->head, queue_item, entries);
	TRACE_OUT(cache_queue_policy_remove_item);
}
Esempio n. 23
0
int LSearch::step(int steps) {
	TRACE_IN("LSearch::LSearch");

	for (int i=0; i<steps; i++) {
		currentVal = localSearch(currSolution, currentVal);

		stat->addGlobalBest(currentVal);
		stat->psoStepDone();

	}
	TRACE_OUT("LSearch::LSearch", 0);
	return 0;
}
Esempio n. 24
0
static struct cache_policy_item_ *
cache_queue_policy_get_next_item(struct cache_policy_ *policy,
	struct cache_policy_item_ *item)
{
	struct cache_queue_policy_ *queue_policy;
	struct cache_queue_policy_item_	*queue_item;

	TRACE_IN(cache_queue_policy_get_next_item);
	queue_policy = (struct cache_queue_policy_ *)policy;
	queue_item = (struct cache_queue_policy_item_ *)item;

	TRACE_OUT(cache_queue_policy_get_next_item);
	return ((struct cache_policy_item_ *)TAILQ_NEXT(queue_item, entries));
}
Esempio n. 25
0
/*
 * The functions below are used to process write requests.
 * - on_transform_request_read1 and on_transform_request_read2 read the
 *   request itself
 * - on_transform_request_process processes it
 * - on_transform_response_write1 sends the response
 */
static int
on_transform_request_read1(struct query_state *qstate)
{
	struct cache_transform_request *transform_request;
	ssize_t	result;

	TRACE_IN(on_transform_request_read1);
	if (qstate->kevent_watermark == 0)
		qstate->kevent_watermark = sizeof(size_t) + sizeof(int);
	else {
		init_comm_element(&qstate->request, CET_TRANSFORM_REQUEST);
		transform_request =
			get_cache_transform_request(&qstate->request);

		result = qstate->read_func(qstate,
			&transform_request->entry_length, sizeof(size_t));
		result += qstate->read_func(qstate,
			&transform_request->transformation_type, sizeof(int));

		if (result != sizeof(size_t) + sizeof(int)) {
			TRACE_OUT(on_transform_request_read1);
			return (-1);
		}

		if ((transform_request->transformation_type != TT_USER) &&
		    (transform_request->transformation_type != TT_ALL)) {
			TRACE_OUT(on_transform_request_read1);
			return (-1);
		}

		if (transform_request->entry_length != 0) {
			if (BUFSIZE_INVALID(transform_request->entry_length)) {
				TRACE_OUT(on_transform_request_read1);
				return (-1);
			}

			transform_request->entry = (char *)calloc(1,
				transform_request->entry_length + 1);
			assert(transform_request->entry != NULL);

			qstate->process_func = on_transform_request_read2;
		} else
			qstate->process_func = on_transform_request_process;

		qstate->kevent_watermark = transform_request->entry_length;
	}

	TRACE_OUT(on_transform_request_read1);
	return (0);
}
Esempio n. 26
0
static int DpsSearchdSendWordRequest(DPS_AGENT *query, const DPS_DB *cl, const char *q) {
	DPS_SEARCHD_PACKET_HEADER hdr;
	ssize_t	nsent;
	size_t  nitems =  (query->flags & DPS_FLAG_UNOCON) ? query->Conf->dbl.nitems : query->dbl.nitems;

	TRACE_IN(query, "DpsSearchdSendWordRequest");
	
	hdr.cmd = (nitems > 1) ? DPS_SEARCHD_CMD_WORDS_ALL : DPS_SEARCHD_CMD_WORDS;
	hdr.len = dps_strlen(q);
	nsent = DpsSearchdSendPacket(cl->searchd, &hdr, q);

	TRACE_OUT(query);
	return DPS_OK;
}
Esempio n. 27
0
/*
 * Handles close notifications. Commits the session by calling
 * the close_cache_mp_write_session.
 */
static int
on_mp_write_session_close_notification(struct query_state *qstate)
{
	TRACE_IN(on_mp_write_session_close_notification);
	configuration_lock_entry(qstate->config_entry, CELT_MULTIPART);
	close_cache_mp_write_session((cache_mp_write_session)qstate->mdata);
	configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART);
	qstate->mdata = INVALID_CACHE_MP_WRITE_SESSION;

	qstate->kevent_watermark = 0;
	qstate->process_func = NULL;
	TRACE_OUT(on_mp_write_session_close_notification);
	return (0);
}
Esempio n. 28
0
struct configuration_entry *
configuration_find_entry(struct configuration *config,
	const char *name)
{
	struct configuration_entry	**retval;

	TRACE_IN(configuration_find_entry);

	retval = bsearch(name, config->entries, config->entries_size,
		sizeof(struct configuration_entry *), configuration_entry_cmp);
	TRACE_OUT(configuration_find_entry);

	return ((retval != NULL) ? *retval : NULL);
}
Esempio n. 29
0
static void
set_negative_confidence_threshold(struct configuration *config,
	const char *entry_name, int conf_thresh)
{
	struct configuration_entry *entry;

	TRACE_IN(set_negative_conf_thresh);
	assert(conf_thresh > 0);
	assert(entry_name != NULL);
	entry = find_create_entry(config, entry_name);
	assert(entry != NULL);
	entry->negative_cache_params.confidence_threshold = conf_thresh;
	TRACE_OUT(set_negative_conf_thresh);
}
Esempio n. 30
0
void
destroy_query_state(struct query_state *qstate)
{

	TRACE_IN(destroy_query_state);
	if (qstate->eid_str != NULL)
	    free(qstate->eid_str);

	if (qstate->io_buffer != NULL)
		free(qstate->io_buffer);

	qstate->destroy_func(qstate);
	free(qstate);
	TRACE_OUT(destroy_query_state);
}