Skip to content
Snippets Groups Projects
Commit c8bd5ea9 authored by Constantin Jucovschi's avatar Constantin Jucovschi
Browse files

update

parent 0444fed7
No related branches found
No related tags found
No related merge requests found
Showing
with 243 additions and 40 deletions
......@@ -86,7 +86,7 @@
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.officebase.impl*</Private-Package>
<Export-Package>info.kwarc.sally4.officebase*;libs*</Export-Package>
<Export-Package>info.kwarc.sally4.officebase*;info.kwarc.sally.comm.select*;libs*</Export-Package>
</instructions>
</configuration>
</plugin>
......
......@@ -3,6 +3,8 @@ package info.kwarc.sally4.officebase.factories;
import info.kwarc.sally4.docmanager.SallyDoc;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import org.apache.felix.ipojo.ComponentInstance;
......@@ -15,6 +17,10 @@ import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.apache.felix.ipojo.annotations.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Instantiate
......@@ -22,11 +28,50 @@ public class OfficeBaseFactory {
@Requires(filter="(factory.name=SelectInstance)")
Factory selectWorkflows;
void createInstance(Factory factory, String name, String docQueue) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
@Requires
SallyDoc[] docs;
Logger log;
public OfficeBaseFactory() {
log = LoggerFactory.getLogger(getClass());
}
final String[] req = {"select", "theo"};
HashMap<String, HashMap<String, SallyDoc>> paired = new HashMap<String, HashMap<String,SallyDoc>>();
HashSet<String> doneEnvironments = new HashSet<String>();
void addDoc(SallyDoc doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
String dq = doc.getEnvironmentID();
if (!paired.containsKey(dq)) {
paired.put(dq, new HashMap<String, SallyDoc>());
}
for (String iFace : doc.getInterfaces()) {
if (paired.get(dq).containsKey(iFace))
continue;
paired.get(dq).put(iFace, doc);
}
if (doneEnvironments.contains(dq))
return;
for (String r : req) {
if (!paired.get(dq).containsKey(r)) {
log.info(">>>>failed at req "+r);
return;
}
}
doneEnvironments.add(dq);
createInstance(selectWorkflows, "Select", paired.get(dq).get("select").getDocQueue(), paired.get(dq).get("theo").getDocQueue(), dq);
}
void createInstance(Factory factory, String name, String docQueue, String theoQueue, final String env) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
Dictionary<String, Object> filters = new Hashtable<String, Object>();
filters.put("docQueue", "(docQueue="+docQueue+")");
filters.put("theoQueue", "(docQueue="+theoQueue+")");
configuration.put("requires.filters", filters);
......@@ -39,18 +84,34 @@ public class OfficeBaseFactory {
public void stateChanged(ComponentInstance arg0, int arg1) {
if (arg1 == ComponentInstance.INVALID) {
arg0.dispose();
doneEnvironments.remove(env);
}
}
});
}
public static <T> boolean contains( final T[] array, final T v ) {
for ( final T e : array )
if ( e == v || v != null && v.equals( e ) )
return true;
return false;
}
@Validate
void start() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
for (SallyDoc doc : docs) {
addDoc(doc);
}
}
@Bind(aggregate=true)
void newSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
for (String iface : newDoc.getInterfaces()) {
if ("select".equals(iface)) {
createInstance(selectWorkflows, "SelectClient", newDoc.getDocQueue());
return;
}
addDoc(newDoc);
}
@Unbind(aggregate=true)
void removeSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
//removeDoc(newDoc);
}
}
package info.kwarc.sally4.officebase.impl;
import info.kwarc.sally.comm.select.Onsallyframe;
import info.kwarc.sally.comm.theo.Opentheowindow;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.core.SallyInteraction;
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.marshalling.CommUtils;
import info.kwarc.sally4.marshalling.MarshallUtils;
import info.kwarc.sally4.officebase.SelectClient;
import info.kwarc.sally4.processors.TypedCallback;
import info.kwarc.sally4.processors.XMLMessageWithTypeInfo;
import info.kwarc.sally4.servlet.SallyServlet;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
@Component(name="SelectInstance")
@Provides(specifications=SelectClient.class)
public class OfficeBaseInstance extends RouteBuilder implements SelectClient{
String planetaryClientNamespace = "http://kwarc.info/sally/comm/planetaryclient";
public class OfficeBaseInstance extends RouteBuilder implements SelectClient, TypedCallback<XMLMessageWithTypeInfo>{
String officeNamespace = "http://kwarc.info/sally/comm/select";
@Requires
SallyServlet t;
@Requires(id="docQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc route;
SallyDoc alexRoute;
@Requires(id="theoQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc theoRoute;
@Requires
SallyInteraction interact;
......@@ -31,8 +42,23 @@ public class OfficeBaseInstance extends RouteBuilder implements SelectClient{
@Requires
CamelContextProvider camelContextProvider;
CamelContext context;
@Validate
void doStart() {
void doStart() throws Exception {
log.info(">>>>Starting OfficeBaseInstance");
alexRoute.addMessageHandler(this);
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addComponent("alex", alexRoute.getAlexComponent());
context.addComponent("theo", theoRoute.getAlexComponent());
context.addRoutes(this);
context.start();
}
@Invalidate
void doStop() throws Exception {
context.stop();
}
public OfficeBaseInstance() {
......@@ -40,16 +66,41 @@ public class OfficeBaseInstance extends RouteBuilder implements SelectClient{
@Override
public void configure() throws Exception {
DataFormat worker = CommUtils.getDataFormat("mathhubworker", getClass().getClassLoader());
getContext().addComponent("alex", route.getAlexComponent());
from("direct:start")
.to("direct:requestAuthKey");
DataFormat select = CommUtils.getDataFormat("select", getClass().getClassLoader());
DataFormat theo = CommUtils.getDataFormat("theo", getClass().getClassLoader());
log.info(">>>> Theo="+theo);
from("direct:sendTheo")
.marshal(theo)
.to("theo:default");
}
@Override
public SallyDoc getDoc() {
return route;
return alexRoute;
}
@Override
public boolean run(XMLMessageWithTypeInfo obj) {
if (!officeNamespace.equals(obj.getXmlMessageNamespace())) {
return false;
}
String body = obj.getXmlString();
log.info(">>>> got message = "+body);
Object msg = MarshallUtils.unmarshallFromXML("select", body, getClass().getClassLoader());
log.info(">>>> message = "+msg);
if (msg instanceof Onsallyframe) {
Onsallyframe frame = (Onsallyframe) msg;
Opentheowindow theoWindow = new Opentheowindow();
theoWindow.setPosx(frame.getPosx());
theoWindow.setPosy(frame.getPosy());
theoWindow.setTitle("Please select");
theoWindow.setUrl("http://localhost:8181/sally/theo");
log.info(">>>> sending theo open");
getContext().createProducerTemplate().sendBody("direct:sendTheo", theoWindow);
}
return true;
}
}
......@@ -54,7 +54,7 @@
<Bundle-Activator>info.kwarc.sally4.core.impl.Activator</Bundle-Activator>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.core.impl</Private-Package>
<Export-Package>info.kwarc.sally4.core*;info.kwarc.sally.comm*</Export-Package>
<Export-Package>info.kwarc.sally4.core*;info.kwarc.sally.comm.core*;info.kwarc.sally.comm.theo*</Export-Package>
<Import-Package>*;</Import-Package>
</instructions>
</configuration>
......
......@@ -12,5 +12,5 @@ public interface SallyDoc {
public ProducerConsumerSplitterComponent getAlexComponent();
public String[] getInterfaces();
public void setMessageHandler(TypedCallback<XMLMessageWithTypeInfo> callback);
public void addMessageHandler(TypedCallback<XMLMessageWithTypeInfo> callback);
}
package info.kwarc.sally4.docmanager.impl;
import info.kwarc.sally4.docmanager.SallyDoc;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Unbind;
public class EnvironmentMatcherFactory {
SallyDoc docs[] = new SallyDoc[0];
ResourceRequirements[] requirements;
HashMap<String, ArrayList<SallyDoc>> docIndex = new HashMap<String, ArrayList<SallyDoc>>();
void addDoc(SallyDoc doc) {
String env = doc.getEnvironmentID();
}
void removeDoc(SallyDoc doc) {
}
public EnvironmentMatcherFactory(ResourceRequirements[] requirements) {
this.requirements = requirements;
}
void start(SallyDoc docs[]) {
this.docs = docs;
for (SallyDoc doc : docs) {
addDoc(doc);
}
}
@Bind
public void bindDoc(SallyDoc doc) {
addDoc(doc);
}
@Unbind
public void unbindDoc(SallyDoc doc) {
removeDoc(doc);
}
}
package info.kwarc.sally4.docmanager.impl;
public class ResourceRequirements {
boolean matchAll;
String [] requirements;
public ResourceRequirements(String [] requirements) {
this(requirements, false);
}
public ResourceRequirements(String [] requirements, Boolean matchAll)
{
this.requirements = requirements;
this.matchAll = matchAll;
}
public String[] getRequirements() {
return requirements;
}
public boolean isMatchAll() {
return matchAll;
}
}
package info.kwarc.sally4.docmanager.impl;
import java.util.HashSet;
import info.kwarc.sally.comm.core.Heartbeatrequest;
import info.kwarc.sally4.components.ProducerConsumerSplitterComponent;
import info.kwarc.sally4.core.CamelContextProvider;
......@@ -49,7 +51,7 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc {
CamelContext camelContext;
TypedCallback<XMLMessageWithTypeInfo> messageHandler;
HashSet<TypedCallback<XMLMessageWithTypeInfo>> messageHandlers;
Logger log;
......@@ -63,10 +65,11 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc {
public SallyDocImpl() {
log = LoggerFactory.getLogger(getClass());
messageHandlers = new HashSet<TypedCallback<XMLMessageWithTypeInfo>>();
}
public SallyDocImpl(String docQueue, String environmentid, String userid, String docStateQueue, String[] interfaces) {
log = LoggerFactory.getLogger(getClass());
this();
this.docQueue = docQueue;
this.environmentid = environmentid;
this.userid = userid;
......@@ -117,7 +120,7 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc {
/**
* Sends a Heartbeat message to the Alex. if it does not respond after 20sec, this route will shutdown.
*/
from("timer://foo?fixedRate=true&period=60000")
from("timer://foo?fixedRate=true&period=10000")
.id("timer")
.bean(method(this, "generateHeartbeat"))
.marshal(core)
......@@ -154,15 +157,17 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc {
}
@Override
public void setMessageHandler(TypedCallback<XMLMessageWithTypeInfo> callback) {
messageHandler = callback;
public void addMessageHandler(TypedCallback<XMLMessageWithTypeInfo> callback) {
messageHandlers.add(callback);
}
public String triggerOnMessageHandlers(Exchange exchange) {
XMLMessageWithTypeInfo info = exchange.getIn().getBody(XMLMessageWithTypeInfo.class);
info.setExchange(exchange);
if (messageHandler != null) {
messageHandler.run(info);
for (TypedCallback<XMLMessageWithTypeInfo> handler : messageHandlers) {
if (handler.run(info)) {
break;
}
}
return exchange.getIn().getBody(String.class);
}
......
......@@ -15,7 +15,8 @@ stomp_args =
# debug: true,
handler = (body, msg) =>
console.log(msg);
if body.opentheowindow?
createNewWindow(body.opentheowindow)
sally = new SallyClient stomp_args, handler
sally.connect ["theo"], (body, msg)->
......
......@@ -23,7 +23,9 @@
};
handler = function(body, msg) {
return console.log(msg);
if (body.opentheowindow != null) {
return createNewWindow(body.opentheowindow);
}
};
sally = new SallyClient(stomp_args, handler);
......
......@@ -75,6 +75,7 @@ class SallyClient
stompMsgHandler : (msg, msgHeaders) =>
msg = msg[0];
console.log(msg);
body = xml2js.parseString msg, (err,body) =>
if body["heartbeatrequest"]? and body["heartbeatrequest"]["$"]["xmlns"] == "http://kwarc.info/sally/comm/core"
......
......@@ -114,6 +114,7 @@ SallyClient = (function() {
var body,
_this = this;
msg = msg[0];
console.log(msg);
return body = xml2js.parseString(msg, function(err, body) {
if ((body["heartbeatrequest"] != null) && body["heartbeatrequest"]["$"]["xmlns"] === "http://kwarc.info/sally/comm/core") {
_this.send(msgHeaders["reply-to"], {
......
......@@ -7,8 +7,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import com.sun.xml.txw2.annotation.XmlNamespace;
public class EnrichMessageProperties implements Processor {
static final public String MessageType = "XMLMessageType";
......@@ -28,6 +26,7 @@ public class EnrichMessageProperties implements Processor {
String namespace = m.group(6);
result.setXmlMessageNamespace(namespace);
result.setXmlMessageType(msgType);
result.setXmlString(body);
exchange.getIn().setBody(result);
} else {
exchange.setException(new Exception("Could not detect namespace in incoming message"));
......
package info.kwarc.sally4.processors;
public interface TypedCallback<T> {
void run(T obj);
boolean run(T obj);
}
......@@ -6,10 +6,18 @@ public class XMLMessageWithTypeInfo {
Exchange exchange;
String xmlMessageType;
String xmlMessageNamespace;
String xmlString;
public XMLMessageWithTypeInfo() {
}
public String getXmlString() {
return xmlString;
}
public void setXmlString(String xmlString) {
this.xmlString = xmlString;
}
public Exchange getExchange() {
return exchange;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment