All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.kwarc.sally4.registration.models.ClientManagerModel Maven / Gradle / Ivy

The newest version!
package info.kwarc.sally4.registration.models;

import info.kwarc.sally.comm.core.RegisterClientRequest;
import info.kwarc.sally.comm.core.RegisterClientResponse;
import info.kwarc.sally4.registration.ClientManager;
import info.kwarc.sally4.util.InstanceCreator;

import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientManagerModel implements ClientManager  {

	Logger log;

	private Factory factory;
	
	public ClientManagerModel(Factory factory) {
		log = LoggerFactory.getLogger(getClass());
		this.factory = factory;
	}
	
	String generateUUID(String doc_queue) {
		//"/queue/sally_doc_"+UUID.randomUUID().toString()
		return "sally_doc_"+doc_queue;
	}
		
	@Override
	public RegisterClientResponse registerDocument(RegisterClientRequest doc) {
		log.info("Registering "+doc.getListenQueue());
		String docQueue = generateUUID(doc.getListenQueue());
		RegisterClientResponse response = new RegisterClientResponse();
		response.setSendQueue(docQueue);
			
			try {
				InstanceCreator.init(factory)
					.setProperty("docQueue", doc.getListenQueue())
					.setProperty("environmentid", doc.getEnvironmentID())
					.setProperty("docStateQueue", docQueue)
					.setProperty("schemas", doc.getSchemas().toArray(new String[0]))
					.setInstanceName("doc:"+doc.getListenQueue())
					.create();
			} catch (UnacceptableConfiguration e) {
				log.error(e.getMessage());
				e.printStackTrace();
			} catch (MissingHandlerException e) {
				log.error(e.getMessage());
				e.printStackTrace();
			} catch (ConfigurationException e) {
				log.error(e.getMessage());
				e.printStackTrace();
			}

		return response;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy