diff --git a/libs/SofiaKPWrapper_jar/SofiaKPWrapper.jar b/libs/SofiaKPWrapper_jar/SofiaKPWrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..76c195b6869a9a8e7ee775ae1f2377255d1268f9 Binary files /dev/null and b/libs/SofiaKPWrapper_jar/SofiaKPWrapper.jar differ diff --git a/src/wrapper/SmartSpaceKPI.java b/src/wrapper/SmartSpaceKPI.java index 151f08d8cd0b0dd4b87019fd1fc4fd5cfbec0dcc..668e2549cb312b269332466babd68b1cac5bf0a1 100644 --- a/src/wrapper/SmartSpaceKPI.java +++ b/src/wrapper/SmartSpaceKPI.java @@ -11,10 +11,12 @@ public class SmartSpaceKPI { private KPICore core; private ArrayList subscriptionIdList; + private ArrayList tripletList; public SmartSpaceKPI(String host, int port, String spaceName) throws SmartSpaceException { core = new KPICore(host, port, spaceName); subscriptionIdList = new ArrayList(); + tripletList = new ArrayList(); SIBResponse joinResponse = core.join(); @@ -28,8 +30,8 @@ public class SmartSpaceKPI { SIBResponse insertResponse = core.insert(triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), triplet.getSubjectType(), triplet.getObjectType()); if (!insertResponse.isConfirmed()) { String text = String.format("KPI failed to insert triplet: (%s, %s, %s, %s, %s)", - triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), - triplet.getSubjectType(), triplet.getObjectType()); + triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), + triplet.getSubjectType(), triplet.getObjectType()); throw new SmartSpaceException(text + '\n' + insertResponse.Message); } @@ -39,8 +41,8 @@ public class SmartSpaceKPI { SIBResponse removeResponse = core.remove(triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), triplet.getSubjectType(), triplet.getObjectType()); if (!removeResponse.isConfirmed()) { String text = String.format("KP failed to remove triplet: (%s, %s, %s, %s, %s)", - triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), - triplet.getSubjectType(), triplet.getObjectType()); + triplet.getSubject(), triplet.getPredicate(), triplet.getObject(), + triplet.getSubjectType(), triplet.getObjectType()); throw new SmartSpaceException(text + '\n' + removeResponse.Message); } @@ -84,6 +86,7 @@ public class SmartSpaceKPI { if (subscribeResponse != null && subscribeResponse.isConfirmed()) { subscriptionIdList.add(subscribeResponse.subscription_id); + tripletList.add(triplet); } else { System.err.println("Some problems with subscribing"); throw new SmartSpaceException(subscribeResponse != null ? subscribeResponse.Message : null); @@ -94,9 +97,7 @@ public class SmartSpaceKPI { try { unsubscribe(); - } - catch (SmartSpaceException exception) - { + } catch (SmartSpaceException exception) { System.err.println(exception.getMessage()); } @@ -127,4 +128,39 @@ public class SmartSpaceKPI { throw new SmartSpaceException(exceptionMessage); } } + + public void unsubscribe(SmartSpaceTriplet triplet, boolean fullMatch) throws SmartSpaceException { + String exceptionMessage = ""; + + String subject = triplet.getSubject(), predicate = triplet.getPredicate(), object = triplet.getObject(); + + for (int i = 0; i < subscriptionIdList.size(); i++) { + SmartSpaceTriplet curTriplet = tripletList.get(i); + + if (checkTwoStrings(subject, curTriplet.getSubject(), fullMatch) && + checkTwoStrings(predicate, curTriplet.getPredicate(), fullMatch) && + checkTwoStrings(object, curTriplet.getObject(), fullMatch)) { + SIBResponse unsubscribeResponse = core.unsubscribe(subscriptionIdList.get(i)); + + // у нас проблемы с отпиской от интеллектуального пространства + if (!unsubscribeResponse.isConfirmed()) { + exceptionMessage += subscriptionIdList.get(i) + ": " + unsubscribeResponse.Message + '\n'; + } + } + } + + // проблемы во время отписки были, сигнализируем это + if (!exceptionMessage.isEmpty()) { + throw new SmartSpaceException(exceptionMessage); + } + } + + private boolean checkTwoStrings(String mainString, String curString, boolean fullMatch) { + if (mainString == null) + if (fullMatch) + return (curString == null); + else + return true; + return mainString.equals(curString); + } }