Skip to content
Snippets Groups Projects
Commit e91af14f authored by Carsten Stocklöw's avatar Carsten Stocklöw
Browse files

some updates, e.g. showing filtering for provider in service bus matchmaking

parent 21d9b613
No related branches found
No related tags found
No related merge requests found
/*
Copyright 2007-2014 Fraunhofer IGD, http://www.igd.fraunhofer.de
Fraunhofer-Gesellschaft - Institut fr Graphische Datenverarbeitung
Fraunhofer-Gesellschaft - Institut fr Graphische Datenverarbeitung
*/
package org.universAAL.tools.logmonitor;
......@@ -30,11 +30,18 @@ public class LogMonitor implements LogListener {
public void log(int logLevel, String module, String pkg, String cls,
String method, Object[] msgPart, Throwable t) {
if (msgPart == null)
msgPart = new Object[0];
for (int i = 0; i < listeners.length; i++)
listeners[i].log(logLevel, module, pkg, cls, method, msgPart, t);
for (int i = 0; i < listeners.length; i++) {
try {
listeners[i]
.log(logLevel, module, pkg, cls, method, msgPart, t);
} catch (Exception e) {
System.out.println("Error found in LogMonitor: ");
e.printStackTrace();
}
}
}
}
......@@ -94,6 +94,7 @@ public class LogMonitor implements LogListenerEx {
* 1011: ProcessResult "requested effect not offered" (none available)
* 1012: ProcessResult "number of effects do not match"
* 1013: ProcessResult "requested effect not offered"
* 1010: ServiceStrategy "No service available."
* 1020: ServiceRealization "no subset relationship for restricted property"
* 1021: ServiceRealization "no subset relationship for restricted property"
* 1022: ServiceRealization "no subset relationship for restricted property"
......@@ -108,20 +109,25 @@ public class LogMonitor implements LogListenerEx {
if (!"mw.bus.service.osgi".equals(module))
return;
Long id = null;
try {
id = (Long) msgPart[msgPart.length - 1];
} catch (Exception e) {
}
if (id == null)
return;
if ("ServiceStrategy".equals(cls))
handleServiceStrategyMessage(msgPart);
handleServiceStrategyMessage(id, msgPart);
else if ("ServiceRealization".equals(cls))
handleServiceRealizationMessage(msgPart);
handleServiceRealizationMessage(id, msgPart);
else if ("ProcessResult".equals(cls))
handleProcessResultMessage(msgPart, method);
handleProcessResultMessage(id, msgPart, method);
}
}
private void handleProcessResultMessage(Object[] msgPart, String method) {
Long id = (Long) msgPart[msgPart.length - 1];
if (id == null)
return;
private void handleProcessResultMessage(Long id, Object[] msgPart,
String method) {
if (ServiceBus.LOG_MATCHING_MISMATCH.equals(msgPart[0])) {
Matchmaking m = (Matchmaking) threads.get(id);
if (m == null) {
......@@ -150,11 +156,7 @@ public class LogMonitor implements LogListenerEx {
}
}
private void handleServiceRealizationMessage(Object[] msgPart) {
Long id = (Long) msgPart[msgPart.length - 1];
if (id == null)
return;
private void handleServiceRealizationMessage(Long id, Object[] msgPart) {
if (ServiceBus.LOG_MATCHING_MISMATCH.equals(msgPart[0])) {
Matchmaking m = (Matchmaking) threads.get(id);
if (m == null) {
......@@ -170,11 +172,7 @@ public class LogMonitor implements LogListenerEx {
}
}
private void handleServiceStrategyMessage(Object[] msgPart) {
Long id = (Long) msgPart[msgPart.length - 1];
if (id == null)
return;
private void handleServiceStrategyMessage(Long id, Object[] msgPart) {
// System.out.println("--- ServiceBus.LOG_MATCHING_SUCCESS: "
// + ServiceBus.LOG_MATCHING_SUCCESS);
......@@ -195,12 +193,29 @@ public class LogMonitor implements LogListenerEx {
} else if (ServiceBus.LOG_MATCHING_NOSUCCESS.equals(msgPart[0])) {
// matching for one profile with the request was not successful
endMatching(id, false);
} else if (ServiceBus.LOG_MATCHING_PROFILES_END.equals(msgPart[0])) {
// the matching with each single profile is done, next step is the
// filtering
endProfileMatching(id, (Integer) msgPart[2]);
} else if (ServiceBus.LOG_MATCHING_PROVIDER_END.equals(msgPart[0])) {
endProviderMatching(id, msgPart);
} else if (ServiceBus.LOG_MATCHING_END.equals(msgPart[0])) {
// matching done
endMatching(id, (Integer) msgPart[2]);
if (msgPart.length == 7)
endMatching(id, msgPart);
else
endMatching(id, (Integer) msgPart[2]);
}
}
private Matchmaking getMatchmaking(Long id, String methodName) {
Matchmaking m = (Matchmaking) threads.get(id);
if (m == null)
throw new IllegalArgumentException("ERROR in matching log tool: "
+ methodName + ", id not available.");
return m;
}
private String getProfileURI(ServiceProfile profile) {
return profile.getTheService().getURI();
}
......@@ -227,12 +242,7 @@ public class LogMonitor implements LogListenerEx {
private void startMatching(Long id, String profileServiceClassURI,
String profileServiceURI, String profileProviderURI) {
// start matchmaking for one profile with the request
Matchmaking m = (Matchmaking) threads.get(id);
if (m == null) {
System.out
.println("ERROR in matching log tool: start matching, but id not available.");
return;
}
Matchmaking m = getMatchmaking(id, "startMatching");
// find the profile; if not available, query it
if (!profiles.containsKey(profileServiceURI)) {
......@@ -263,18 +273,35 @@ public class LogMonitor implements LogListenerEx {
}
private void endMatching(Long id, boolean success) {
Matchmaking m = (Matchmaking) threads.get(id);
Matchmaking m = getMatchmaking(id, "endMatching, success: " + success);
SingleMatching single = (SingleMatching) m.matchings.getLast();
single.success = Boolean.valueOf(success);
}
private void endMatching(Long id, Integer numMatches) {
Matchmaking m = (Matchmaking) threads.get(id);
if (m == null) {
System.out
.println("ERROR in matching log tool: endMatching, id not available.");
return;
private void endMatching(Long id, Object[] msgPart) {
// no service has been found
Matchmaking m = getMatchmaking(id, "endMatching (no-service)");
m.registeredServicesAvailable = false;
m.numMatches = 0;
m.success = Boolean.FALSE;
finish(id, m);
}
private void endProfileMatching(Long id, Integer numMatches) {
Matchmaking m = getMatchmaking(id, "endProfileMatching");
m.numMatchingProfiles = numMatches.intValue();
}
private void endProviderMatching(Long id, Object[] msgPart) {
Matchmaking m = getMatchmaking(id, "endProviderMatching");
m.numMatchingAfterProviderFilter = (Integer) msgPart[2];
for (int i = 4; i < msgPart.length - 1; i++) {
m.matchingsProvFilt.add((String) msgPart[i]);
}
}
private void endMatching(Long id, Integer numMatches) {
Matchmaking m = getMatchmaking(id, "endMatching (final)");
m.numMatches = numMatches.intValue();
if (m.numMatches != 0)
......@@ -282,9 +309,12 @@ public class LogMonitor implements LogListenerEx {
else
m.success = Boolean.FALSE;
finish(id, m);
}
private void finish(Long id, Matchmaking m) {
// print(m);
threads.remove(id);
gui.notify(m);
}
......
......@@ -81,7 +81,13 @@ public class Matchmaking {
// true, iff the request has some matches. In this case: numMatches > 0
public Boolean success = null;
// the number of matches
// the number of matches after testing all profiles, before filtering
public int numMatchingProfiles = -1;
// the number of matches after filtering for providers
public int numMatchingAfterProviderFilter = -1;
// the number of matches at the end
public int numMatches = -1;
// the service request
......@@ -93,12 +99,18 @@ public class Matchmaking {
// URI of the requested service
public String serviceURI;
// the set of single matchings
// the set of single matchings after profile matching and before filtering
public LinkedList<SingleMatching> matchings = new LinkedList<SingleMatching>();
// the set of profile service URIs after filtering for the provider
public LinkedList<String> matchingsProvFilt = new LinkedList<String>();
// the exact time when the matchmaking starts
public Date date;
// error 1010
public boolean registeredServicesAvailable = true;
/**
* Get the date as a string.
*
......
......@@ -397,7 +397,7 @@ public class MatchmakingPane extends JTextPane {
getProfileRequestCommonHTML(s, effects, outputs);
}
private void getOverviewHTML(StringBuilder s, List group) {
private void getOverviewHTML(StringBuilder s, List<SingleMatching> group) {
for (Iterator<SingleMatching> it = group.iterator(); it.hasNext();) {
SingleMatching single = it.next();
String val2 = "-";
......@@ -423,7 +423,7 @@ public class MatchmakingPane extends JTextPane {
private String createHTML(Matchmaking m) {
ProfileInfo info;
LinkedList<SingleMatching> l;
LinkedList<SingleMatching> l = new LinkedList<SingleMatching>();
StringBuilder s = new StringBuilder(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><body>\n");
......@@ -435,57 +435,70 @@ public class MatchmakingPane extends JTextPane {
s.append(getImageHTML("ERROR_32.png"));
s.append("Service request: <b>" + m.serviceURI + "</b><br>");
// ///////////////////////////////////////
// overview of matchings
s.append("<br><br>Matching with registered service profiles:<br>");
s.append(getTableStartHTML(1));
s.append(getTableRowTitleHTML("Result", "Reason", "Service URI"));
if (overviewMethod == 0) {
l = m.matchings;
HashMap<String, ArrayList<SingleMatching>> groups = new HashMap<String, ArrayList<SingleMatching>>();
// create the grouping
for (SingleMatching single : l) {
info = LogMonitor.instance.getProfile(single.profileURI);
String providerURI = "<unknown>";
if (!(info == null) && !(info.profileProviderURI == null))
providerURI = info.profileProviderURI;
ArrayList<SingleMatching> group = groups.get(providerURI);
if (group == null) {
group = new ArrayList<SingleMatching>();
groups.put(providerURI, group);
}
group.add(single);
}
// get a sorted set of provider URIs
ArrayList<String> sortedProviderURIs = new ArrayList<String>(
groups.keySet());
Collections.sort(sortedProviderURIs);
// get the html output
for (String providerURI : sortedProviderURIs) {
ArrayList<SingleMatching> group = groups.get(providerURI);
Collections.sort(group, new Comparator<SingleMatching>() {
public int compare(SingleMatching o1, SingleMatching o2) {
return o1.profileURI.compareTo(o2.profileURI);
if (m.registeredServicesAvailable) {
s.append(getTableStartHTML(1));
s.append(getTableRowTitleHTML("Result", "Reason", "Service URI"));
if (overviewMethod == 0) {
l = m.matchings;
HashMap<String, ArrayList<SingleMatching>> groups = new HashMap<String, ArrayList<SingleMatching>>();
// create the grouping
for (SingleMatching single : l) {
info = LogMonitor.instance.getProfile(single.profileURI);
String providerURI = "<unknown>";
if (!(info == null) && !(info.profileProviderURI == null))
providerURI = info.profileProviderURI;
ArrayList<SingleMatching> group = groups.get(providerURI);
if (group == null) {
group = new ArrayList<SingleMatching>();
groups.put(providerURI, group);
}
});
group.add(single);
}
s.append(getTableRowHTML("Provider: " + providerURI, 3));
getOverviewHTML(s, group);
// get a sorted set of provider URIs
ArrayList<String> sortedProviderURIs = new ArrayList<String>(
groups.keySet());
Collections.sort(sortedProviderURIs);
// we clear the list and add all elements again in a sorted
// order
l.clear();
// get the html output
for (String providerURI : sortedProviderURIs) {
ArrayList<SingleMatching> group = groups.get(providerURI);
Collections.sort(group, new Comparator<SingleMatching>() {
public int compare(SingleMatching o1, SingleMatching o2) {
return o1.profileURI.compareTo(o2.profileURI);
}
});
s.append(getTableRowHTML("Provider: "
+ getURIHTML(providerURI), 3));
getOverviewHTML(s, group);
l.addAll(group);
}
} else {
l = m.matchings;
getOverviewHTML(s, l);
}
s.append(getTableEndHTML());
} else {
l = m.matchings;
getOverviewHTML(s, l);
s.append(" - no services are registered for the requested URI -<br>");
}
s.append(getTableEndHTML());
// details
s.append("<br>");
s.append(getLinkHTML("all", isVisible("all") ? "hide all" : "show all"));
s.append("<br><br>");
// ///////////////////////////////////////
// details for request
s.append("Request: ");
......@@ -514,92 +527,137 @@ public class MatchmakingPane extends JTextPane {
// s.append(getLink("requestQuery", "show query (experimentel)"));
// }
// details for each matchmaking
l = m.matchings;
for (Iterator<SingleMatching> it = l.iterator(); it.hasNext();) {
SingleMatching single = it.next();
s.append("<hr><h2>Details for " + URI.get(single.profileURI, true)
+ "</h2>\n\n");
if (m.registeredServicesAvailable) {
// ///////////////////////////////////////
// details for each matchmaking
for (Iterator<SingleMatching> it = l.iterator(); it.hasNext();) {
SingleMatching single = it.next();
s.append("<hr><h2>Details for "
+ URI.get(single.profileURI, true) + "</h2>\n\n");
if (single.success.booleanValue()) {
s.append(getImageHTML("OK_16.png") + "&#160;&#160;");
s.append("successful");
if (single.success.booleanValue()) {
s.append(getImageHTML("OK_16.png") + "&#160;&#160;");
s.append("successful");
} else {
s.append(getImageHTML("ERROR_16.png") + "&#160;&#160;");
switch (single.reason) {
case SingleMatching.REASON_INPUT:
String prop = single.restrictedProperty;
if (prop == null)
s.append(" input: number of input parameters do not match");
else
s.append(" input: input parameters do not match for property "
+ getURIHTML(prop));
break;
case SingleMatching.REASON_OUTPUT:
s.append(" output: ");
s.append(single.code);
s.append(" - ");
s.append(single.shortReason);
s.append("<br>\n<i>Details:</i> ");
s.append(single.detailedReason);
s.append("<br>\n");
if (single.output != null)
s.append(getOutputHTML(single.output));
else
System.out.println("ERROR: no output found");
break;
case SingleMatching.REASON_EFFECT:
s.append(" effect: ");
s.append(single.code);
s.append(" - ");
s.append(single.shortReason);
s.append("<br>\n<i>Details:</i> ");
s.append(single.detailedReason);
s.append("<br>\n");
s.append("<br>\n");
if (single.effect != null)
s.append(getEffectHTML(single.effect));
break;
default:
s.append("reason unknown");
} else {
s.append(getImageHTML("ERROR_16.png") + "&#160;&#160;");
switch (single.reason) {
case SingleMatching.REASON_INPUT:
String prop = single.restrictedProperty;
if (prop == null)
s.append(" input: number of input parameters do not match");
else
s.append(" input: input parameters do not match for property "
+ getURIHTML(prop));
break;
case SingleMatching.REASON_OUTPUT:
s.append(" output: ");
s.append(single.code);
s.append(" - ");
s.append(single.shortReason);
s.append("<br>\n<i>Details:</i> ");
s.append(single.detailedReason);
s.append("<br>\n");
if (single.output != null)
s.append(getOutputHTML(single.output));
else
System.out.println("ERROR: no output found");
break;
case SingleMatching.REASON_EFFECT:
s.append(" effect: ");
s.append(single.code);
s.append(" - ");
s.append(single.shortReason);
s.append("<br>\n<i>Details:</i> ");
s.append(single.detailedReason);
s.append("<br>\n");
s.append("<br>\n");
if (single.effect != null)
s.append(getEffectHTML(single.effect));
break;
default:
s.append("reason unknown");
}
}
}
s.append("<br>\n");
s.append("<br>\n");
s.append("ServiceProfile: ");
info = LogMonitor.instance.getProfile(single.profileURI);
if (info == null || info.profile == null)
s.append("- unknown -<br>\n");
else {
ServiceProfile profile = info.profile;
String link = "ServiceProfile_" + single.profileURI;
String link_abstract = link + "_abstract";
String link_serialized = link + "_serialized";
// ServiceProfile serialized
if (isVisible(link_serialized)) {
s.append(getLinkHTML(link_serialized, "hide serialized"));
if (info.serialized == null) // create on first use
info.serialized = Activator.serialize(profile);
s.append("<pre>\n" + turtle2HTML(info.serialized)
+ "\n</pre>\n");
} else {
s.append(getLinkHTML(link_serialized, "show serialized"));
s.append("ServiceProfile: ");
info = LogMonitor.instance.getProfile(single.profileURI);
if (info == null || info.profile == null)
s.append("- unknown -<br>\n");
else {
ServiceProfile profile = info.profile;
String link = "ServiceProfile_" + single.profileURI;
String link_abstract = link + "_abstract";
String link_serialized = link + "_serialized";
// ServiceProfile serialized
if (isVisible(link_serialized)) {
s.append(getLinkHTML(link_serialized, "hide serialized"));
if (info.serialized == null) // create on first use
info.serialized = Activator.serialize(profile);
s.append("<pre>\n" + turtle2HTML(info.serialized)
+ "\n</pre>\n");
} else {
s.append(getLinkHTML(link_serialized, "show serialized"));
}
// ServiceProfile abstract
if (isVisible(link_abstract)) {
s.append(getLinkHTML(link_abstract,
"hide abstract<br><br>\n"));
getServiceProfileHTML(s, profile);
} else {
s.append(getLinkHTML(link_abstract, "show abstract"));
}
}
}
// ServiceProfile abstract
if (isVisible(link_abstract)) {
s.append(getLinkHTML(link_abstract,
"hide abstract<br><br>\n"));
getServiceProfileHTML(s, profile);
} else {
s.append(getLinkHTML(link_abstract, "show abstract"));
// ///////////////////////////////////////
// filtering : Provider
s.append("<hr><h2>Provider filtering</h2><p>The list of services is filtered,"
+ " so that only <i>one</i> service for a service provider is taken."
+ " If more than one service matches for a provider then the"
+ " most specialized service is taken.</p>\n<p>The number of matching"
+ " services is:</p>\n");
s.append(getTableStartHTML(0));
s.append(getTableRowHTML("before provider filtering:", ""
+ m.numMatchingProfiles));
s.append(getTableRowHTML("after provider filtering:", ""
+ m.numMatchingAfterProviderFilter));
s.append(getTableEndHTML());
s.append("<br>The matched profiles and their provider filtering results are:<br>\n");
s.append(getTableStartHTML(0));
for (SingleMatching single : l) {
if (single.success.booleanValue()) {
String profileURI = single.profileURI;
String res = m.matchingsProvFilt.contains(profileURI) ? "OK_16.png"
: "ERROR_16.png";
s.append(getTableRowHTML(getImageHTML(res),
getURIHTML(profileURI)));
}
}
s.append(getTableEndHTML());
/*
* s.append(getTableStartHTML(0)); for (SingleMatching single : l) {
* if (single.success.booleanValue()) {
* s.append(getTableRowHTML(single.profileURI)); } }
* s.append(getTableEndHTML());
*
* s.append("\n<p>The following " + m.numMatchingAfterProviderFilter
* + " services have are available after filtering:</p>\n");
*
* s.append(getTableStartHTML(0)); for (String srvURI :
* m.matchingsProvFilt) { s.append(getTableRowHTML(srvURI)); }
* s.append(getTableEndHTML());
*/
}
s.append("\n</body></html>");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment