diff --git a/.gitignore b/.gitignore index a061e8b25a1330d44e156bc701b5c50951032a2a..907e23b9fb81458cabc7b7129940eeb0d77bc5c4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ .*.sw[a-z] *.un~ Session.vim +**/manifest.mf +**/*.*~ diff --git a/build.xml b/build.xml index 298d8654b0586cf55a8139513369c45fd9e160e4..b280d792a719da75a4306387ad816c6738213b99 100644 --- a/build.xml +++ b/build.xml @@ -1,4 +1,4 @@ -<project name="ipaaca" default="build" basedir="."> +<project name="ipaaca-all" default="build" basedir="."> <target name="resolve"> <subant target="resolve" genericantfile="build.xml"> <fileset dir="." includes="*/build.xml"/> diff --git a/java/build.properties b/java/build.properties index 8c6fc149f768d847b59e7027cffd5e871b7ef777..de98c805262dd9ae57b3d093aca519cd8c9f2829 100644 --- a/java/build.properties +++ b/java/build.properties @@ -1,6 +1,7 @@ language=java resolve.status=beta resource.path= +publish.resolver=soa.core.repository #resource.path=${shared.repository}/Humanoids;${shared.repository}/3dmodels;${shared.repository}/HMI/HmiElckerlyc/resources;${shared.repository}/logbackconfig;${shared.repository}/shaders; run.jvmargs= -Xms128m -Xmx512m -Xss5M rebuild.list= diff --git a/java/build.xml b/java/build.xml index 210b34a990975a7c828d943e463e603f2a0e1be4..996ee0e6a6851df299e656ba31c531cff1632f34 100644 --- a/java/build.xml +++ b/java/build.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project name="IpaacaJava" default="run"> - <import file="../../soashared/ant/build.xml" /> - +<project name="ipaaca-java" default="run"> + <target name="-pre-compilation"> <echo message="Compiling protobuf file" /> <mkdir dir="generatedsrc"/> @@ -11,4 +10,7 @@ <arg value="--java_out=generatedsrc/" /> </exec> </target> + + <!--import file="../../soashared/ant/build.xml" /--> + <import file="../../HmiBuild/build.xml" /> </project> diff --git a/java/ivy.xml b/java/ivy.xml index fd0007f6e8809662be9819b3bf4212834649c97f..7a5fc340273b483428d9ab46df5d6e6a1ec52c1a 100644 --- a/java/ivy.xml +++ b/java/ivy.xml @@ -1,5 +1,5 @@ <ivy-module version="2.0"> - <info organisation="ipaaca" module="ipaaca"/> + <info organisation="ipaaca" module="ipaaca-java"/> <configurations> <include file="${ivy.settings.dir}/configurations.xml"/> </configurations> diff --git a/java/manifest.mf b/java/manifest.mf index 5f1307134cd9ebfa637c79613ae1249c903beaf7..829110fcd98566df508f0e875a6a85daab1d86b8 100644 --- a/java/manifest.mf +++ b/java/manifest.mf @@ -1,10 +1,10 @@ Manifest-Version: 1.0 -Main-Class: ipaaca.Info - -Name: ipaaca -Specification-Title: ipaaca +Main-Class: main + +Name: IpaacaJava +Specification-Title: IpaacaJava Specification-Version: 0.1 Specification-Vendor: ipaaca -Implementation-Title: ipaaca -Implementation-Version: February 21 2012 05:23 PM -Implementation-Vendor: ipaaca +Implementation-Title: IpaacaJava +Implementation-Version: July 02 2012 01:46 PM +Implementation-Vendor: ipaaca \ No newline at end of file diff --git a/java/src/ipaaca/Buffer.java b/java/src/ipaaca/Buffer.java index f2ea13060aa73cae62e8e554a4b44cab6321c760..e335e1f4175e82a68e8e6b2e7873a724f0c94d87 100644 --- a/java/src/ipaaca/Buffer.java +++ b/java/src/ipaaca/Buffer.java @@ -7,82 +7,82 @@ import java.util.UUID; /** * Base class for InputBuffer and OutputBuffer. */ -public abstract class Buffer { - private final String owningComponentName; - - private List<IUEventHandler> eventHandlers = new ArrayList<IUEventHandler>(); - protected final String uuid = UUID.randomUUID().toString().replaceAll("-",""); - protected String uniqueName; - - public String getUniqueName() { - return uniqueName; - } +public abstract class Buffer +{ + private final String owningComponentName; - public String getOwningComponentName() { - return owningComponentName; - } - - -// def __init__(self, owning_component_name, participant_config=None): -// '''Create a Buffer. -// -// Keyword arguments: -// owning_compontent_name -- -// participant_config -- RSB configuration -// ''' -// super(Buffer, self).__init__() -// self._owning_component_name = owning_component_name -// self._participant_config = participant_config #rsb.ParticipantConfig.fromDefaultSources() if participant_config is None else participant_config -// self._uuid = str(uuid.uuid4())[0:8] -// # Initialise with a temporary, but already unique, name -// self._unique_name = "undef-"+self._uuid -// self._iu_store = IUStore() -// self._iu_event_handlers = [] - /** - * @param owningComponentName name of the entity that owns this Buffer - * @param participantConfig RSB configuration - */ - public Buffer(String owningComponentName) - { - this.owningComponentName = owningComponentName; - uniqueName = "undef-"+uuid; - } + private List<IUEventHandler> eventHandlers = new ArrayList<IUEventHandler>(); + protected final String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + protected String uniqueName; - - -// def register_handler(self, handler_function, for_event_types=None, for_categories=None): -// """Register a new IU event handler function. -// -// Keyword arguments: -// handler_function -- a function with the signature (IU, event_type, local) -// for_event_types -- a list of event types or None if handler should -// be called for all event types -// for_categories -- a list of category names or None if handler should -// be called for all categoires -// -// """ -// handler = IUEventHandler(handler_function=handler_function, for_event_types=for_event_types, for_categories=for_categories) -// self._iu_event_handlers.append(handler) - public void registerHandler(IUEventHandler handler) - { - eventHandlers.add(handler); - } - -// def call_iu_event_handlers(self, uid, local, event_type, category): -// """Call registered IU event handler functions registered for this event_type and category.""" -// for h in self._iu_event_handlers: -// # print('calling an update handler for '+event_type+' -> '+str(h)) -// h.call(self, uid, local=local, event_type=event_type, category=category) - /** - * Call registered IU event handler functions registered for this event_type and category. - */ - public void callIuEventHandlers(String uid, boolean local, IUEventType type, String category) - { - for(IUEventHandler h:eventHandlers) - { - h.call(this, uid, local, type, category); - } - } - - public abstract AbstractIU getIU(String iuid); + public String getUniqueName() + { + return uniqueName; + } + + public String getOwningComponentName() + { + return owningComponentName; + } + + // def __init__(self, owning_component_name, participant_config=None): + // '''Create a Buffer. + // + // Keyword arguments: + // owning_compontent_name -- + // participant_config -- RSB configuration + // ''' + // super(Buffer, self).__init__() + // self._owning_component_name = owning_component_name + // self._participant_config = participant_config #rsb.ParticipantConfig.fromDefaultSources() if participant_config is None else participant_config + // self._uuid = str(uuid.uuid4())[0:8] + // # Initialise with a temporary, but already unique, name + // self._unique_name = "undef-"+self._uuid + // self._iu_store = IUStore() + // self._iu_event_handlers = [] + /** + * @param owningComponentName name of the entity that owns this Buffer + * @param participantConfig RSB configuration + */ + public Buffer(String owningComponentName) + { + this.owningComponentName = owningComponentName; + uniqueName = "undef-" + uuid; + } + + // def register_handler(self, handler_function, for_event_types=None, for_categories=None): + // """Register a new IU event handler function. + // + // Keyword arguments: + // handler_function -- a function with the signature (IU, event_type, local) + // for_event_types -- a list of event types or None if handler should + // be called for all event types + // for_categories -- a list of category names or None if handler should + // be called for all categoires + // + // """ + // handler = IUEventHandler(handler_function=handler_function, for_event_types=for_event_types, for_categories=for_categories) + // self._iu_event_handlers.append(handler) + public void registerHandler(IUEventHandler handler) + { + eventHandlers.add(handler); + } + + // def call_iu_event_handlers(self, uid, local, event_type, category): + // """Call registered IU event handler functions registered for this event_type and category.""" + // for h in self._iu_event_handlers: + // # print('calling an update handler for '+event_type+' -> '+str(h)) + // h.call(self, uid, local=local, event_type=event_type, category=category) + /** + * Call registered IU event handler functions registered for this event_type and category. + */ + public void callIuEventHandlers(String uid, boolean local, IUEventType type, String category) + { + for (IUEventHandler h : eventHandlers) + { + h.call(this, uid, local, type, category); + } + } + + public abstract AbstractIU getIU(String iuid); } diff --git a/java/src/ipaaca/HandlerFunctor.java b/java/src/ipaaca/HandlerFunctor.java index 5f4edbdbd5115c75796bde9b697c95f599ce7ea3..4020b7321978d2ee847081934cc032b9ba399961 100644 --- a/java/src/ipaaca/HandlerFunctor.java +++ b/java/src/ipaaca/HandlerFunctor.java @@ -1,5 +1,6 @@ package ipaaca; -public interface HandlerFunctor { - void handle(AbstractIU iu, IUEventType type, boolean local); +public interface HandlerFunctor +{ + void handle(AbstractIU iu, IUEventType type, boolean local); } diff --git a/java/src/ipaaca/IUAccessMode.java b/java/src/ipaaca/IUAccessMode.java index 6562e012f99610e269f0579c4c33aee2767bb00a..02941316bd71d8e6a8fe899e7228c52d0e0a671b 100644 --- a/java/src/ipaaca/IUAccessMode.java +++ b/java/src/ipaaca/IUAccessMode.java @@ -1,5 +1,6 @@ package ipaaca; -public enum IUAccessMode { - PUSH,REMOTE,MESSAGE; +public enum IUAccessMode +{ + PUSH, REMOTE, MESSAGE; } diff --git a/java/src/ipaaca/IUCommittedException.java b/java/src/ipaaca/IUCommittedException.java index dd079b50da9e311555d1021ed26c6f685fe0fb56..9564de2f8af84d1e6f22cbef7b11dc5027e04f2c 100644 --- a/java/src/ipaaca/IUCommittedException.java +++ b/java/src/ipaaca/IUCommittedException.java @@ -3,19 +3,21 @@ package ipaaca; /** * Error indicating that an IU is immutable because it has been committed to. * @author hvanwelbergen - * + * */ -public class IUCommittedException extends RuntimeException{ - private static final long serialVersionUID = 1L; - private final AbstractIU iu; - - public AbstractIU getIU() { - return iu; - } - - public IUCommittedException(AbstractIU iu) - { - super("Writing to IU " + iu.getUid() + " failed -- it has been committed to."); - this.iu = iu; - } +public class IUCommittedException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + private final AbstractIU iu; + + public AbstractIU getIU() + { + return iu; + } + + public IUCommittedException(AbstractIU iu) + { + super("Writing to IU " + iu.getUid() + " failed -- it has been committed to."); + this.iu = iu; + } } diff --git a/java/src/ipaaca/IUConverter.java b/java/src/ipaaca/IUConverter.java index 7b16418012bd55a351db9998b3520cd65ab9baf7..5f3d46b23573ceec5e057f3e124dc3340264844f 100644 --- a/java/src/ipaaca/IUConverter.java +++ b/java/src/ipaaca/IUConverter.java @@ -1,4 +1,5 @@ package ipaaca; + import ipaaca.protobuf.Ipaaca.IU; import ipaaca.protobuf.Ipaaca.LinkSet; import ipaaca.protobuf.Ipaaca.PayloadItem; @@ -22,17 +23,17 @@ import rsb.converter.WireContents; /** * Serializes AbstractIUs into protocolbuffer IUs and vice versa. * @author hvanwelbergen - * + * */ public class IUConverter implements Converter<ByteBuffer> { private final ConverterSignature signature; - + public IUConverter(ConverterSignature signature) { this.signature = signature; } - + @Override public ConverterSignature getSignature() { @@ -42,36 +43,23 @@ public class IUConverter implements Converter<ByteBuffer> @Override public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException { - AbstractIU iua = (AbstractIU)obj; + AbstractIU iua = (AbstractIU) obj; List<PayloadItem> payloadItems = new ArrayList<PayloadItem>(); - for(Entry<String, String> entry:iua.getPayload().entrySet()) + for (Entry<String, String> entry : iua.getPayload().entrySet()) { - payloadItems.add(PayloadItem.newBuilder() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .setType("") - .build()); + payloadItems.add(PayloadItem.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).setType("").build()); } - + List<LinkSet> links = new ArrayList<LinkSet>(); - for (Entry<String, Collection<String>> entry:iua.getAllLinks().asMap().entrySet()) + for (Entry<String, Collection<String>> entry : iua.getAllLinks().asMap().entrySet()) { links.add(LinkSet.newBuilder().setType(entry.getKey()).addAllTargets(entry.getValue()).build()); } - - IU iu = IU.newBuilder() - .setUid(iua.getUid()) - .setRevision(iua.getRevision()) - .setCategory(iua.getCategory()) - .setOwnerName(iua.getOwnerName()) - .setCommitted(iua.isCommitted()) - .setAccessMode(IU.AccessMode.PUSH) //TODO for other access modes (also in Python version) - .setReadOnly(iua.isReadOnly()) - .setPayloadType("MAP") - .addAllPayload(payloadItems) - .addAllLinks(links) - .build(); - return new WireContents<ByteBuffer>(ByteBuffer.wrap(iu.toByteArray()),"ipaaca-iu"); + + IU iu = IU.newBuilder().setUid(iua.getUid()).setRevision(iua.getRevision()).setCategory(iua.getCategory()) + .setOwnerName(iua.getOwnerName()).setCommitted(iua.isCommitted()).setAccessMode(IU.AccessMode.PUSH) // TODO for other access modes (also in Python version) + .setReadOnly(iua.isReadOnly()).setPayloadType("MAP").addAllPayload(payloadItems).addAllLinks(links).build(); + return new WireContents<ByteBuffer>(ByteBuffer.wrap(iu.toByteArray()), "ipaaca-iu"); } @Override @@ -87,22 +75,22 @@ public class IUConverter implements Converter<ByteBuffer> throw new RuntimeException(e); } - if(iu.getAccessMode() == IU.AccessMode.PUSH) + if (iu.getAccessMode() == IU.AccessMode.PUSH) { RemotePushIU iuout = new RemotePushIU(iu.getUid()); iuout.setCategory(iu.getCategory()); iuout.committed = iu.getCommitted(); iuout.setOwnerName(iu.getOwnerName()); iuout.setRevision(iu.getRevision()); - iuout.setReadOnly(iu.getReadOnly()); - iuout.payload = new Payload(iuout,iu.getPayloadList()); + iuout.setReadOnly(iu.getReadOnly()); + iuout.payload = new Payload(iuout, iu.getPayloadList()); SetMultimap<String, String> links = HashMultimap.create(); - for(LinkSet ls: iu.getLinksList()) + for (LinkSet ls : iu.getLinksList()) { - links.putAll(ls.getType(),ls.getTargetsList()); + links.putAll(ls.getType(), ls.getTargetsList()); } iuout.setLinksLocally(links); - return new UserData<RemotePushIU>(iuout, RemotePushIU.class); + return new UserData<RemotePushIU>(iuout, RemotePushIU.class); } else { diff --git a/java/src/ipaaca/IUEventHandler.java b/java/src/ipaaca/IUEventHandler.java index 85f956fdeb9b5a1531471c00e2f24b032776303d..25f2135f70f7a46e527653fd1347c90d8b5c509d 100644 --- a/java/src/ipaaca/IUEventHandler.java +++ b/java/src/ipaaca/IUEventHandler.java @@ -7,76 +7,78 @@ import java.util.Set; * Wrapper for IU event handling functions. * @author hvanwelbergen */ -public class IUEventHandler { - private final EnumSet<IUEventType> eventTypes; - private Set<String>categories; - private final HandlerFunctor handleFunctor; -// def __init__(self, handler_function, for_event_types=None, for_categories=None): -// """Create an IUEventHandler. -// -// Keyword arguments: -// handler_function -- the handler function with the signature -// (IU, event_type, local) -// for_event_types -- a list of event types or None if handler should -// be called for all event types -// for_categories -- a list of category names or None if handler should -// be called for all categoires -// """ -// super(IUEventHandler, self).__init__() -// self._handler_function = handler_function -// self._for_event_types = ( -// None if for_event_types is None else -// (for_event_types[:] if hasattr(for_event_types, '__iter__') else [for_event_types])) -// self._for_categories = ( -// None if for_categories is None else -// (for_categories[:] if hasattr(for_categories, '__iter__') else [for_categories])) - - public IUEventHandler(HandlerFunctor func, EnumSet<IUEventType> eventTypes, Set<String>categories) - { - this.eventTypes = eventTypes; - this.categories = categories; - this.handleFunctor = func; - } - -// def condition_met(self, event_type, category): -// """Check whether this IUEventHandler should be called. -// -// Keyword arguments: -// event_type -- type of the IU event -// category -- category of the IU which triggered the event -// """ -// type_condition_met = (self._for_event_types is None or event_type in self._for_event_types) -// cat_condition_met = (self._for_categories is None or category in self._for_categories) -// return type_condition_met and cat_condition_met - /** - * Check whether this IUEventHandler should be called. - * @param type type of the IU event - * @param category category of the IU which triggered the event - */ - private boolean conditionMet(IUEventType type, String category) - { - return eventTypes.contains(type) && categories.contains(category); - } - -// def call(self, buffer, iu_uid, local, event_type, category): -// """Call this IUEventHandler's function, if it applies. -// -// Keyword arguments: -// buffer -- the buffer in which the IU is stored -// iu_uid -- the uid of the IU -// local -- is the IU local or remote to this component? @RAMIN: Is this correct? -// event_type -- IU event type -// category -- category of the IU -// """ -// if self.condition_met(event_type, category): -// iu = buffer._iu_store[iu_uid] -// self._handler_function(iu, event_type, local) - public void call(Buffer buf, String iuUid, boolean local, IUEventType type, String category) - { - if(conditionMet(type,category)) - { - AbstractIU iu = buf.getIU(iuUid); - handleFunctor.handle(iu, type, local); - } - } +public class IUEventHandler +{ + private final EnumSet<IUEventType> eventTypes; + private Set<String> categories; + private final HandlerFunctor handleFunctor; + + // def __init__(self, handler_function, for_event_types=None, for_categories=None): + // """Create an IUEventHandler. + // + // Keyword arguments: + // handler_function -- the handler function with the signature + // (IU, event_type, local) + // for_event_types -- a list of event types or None if handler should + // be called for all event types + // for_categories -- a list of category names or None if handler should + // be called for all categoires + // """ + // super(IUEventHandler, self).__init__() + // self._handler_function = handler_function + // self._for_event_types = ( + // None if for_event_types is None else + // (for_event_types[:] if hasattr(for_event_types, '__iter__') else [for_event_types])) + // self._for_categories = ( + // None if for_categories is None else + // (for_categories[:] if hasattr(for_categories, '__iter__') else [for_categories])) + + public IUEventHandler(HandlerFunctor func, EnumSet<IUEventType> eventTypes, Set<String> categories) + { + this.eventTypes = eventTypes; + this.categories = categories; + this.handleFunctor = func; + } + + // def condition_met(self, event_type, category): + // """Check whether this IUEventHandler should be called. + // + // Keyword arguments: + // event_type -- type of the IU event + // category -- category of the IU which triggered the event + // """ + // type_condition_met = (self._for_event_types is None or event_type in self._for_event_types) + // cat_condition_met = (self._for_categories is None or category in self._for_categories) + // return type_condition_met and cat_condition_met + /** + * Check whether this IUEventHandler should be called. + * @param type type of the IU event + * @param category category of the IU which triggered the event + */ + private boolean conditionMet(IUEventType type, String category) + { + return eventTypes.contains(type) && categories.contains(category); + } + + // def call(self, buffer, iu_uid, local, event_type, category): + // """Call this IUEventHandler's function, if it applies. + // + // Keyword arguments: + // buffer -- the buffer in which the IU is stored + // iu_uid -- the uid of the IU + // local -- is the IU local or remote to this component? @RAMIN: Is this correct? + // event_type -- IU event type + // category -- category of the IU + // """ + // if self.condition_met(event_type, category): + // iu = buffer._iu_store[iu_uid] + // self._handler_function(iu, event_type, local) + public void call(Buffer buf, String iuUid, boolean local, IUEventType type, String category) + { + if (conditionMet(type, category)) + { + AbstractIU iu = buf.getIU(iuUid); + handleFunctor.handle(iu, type, local); + } + } } diff --git a/java/src/ipaaca/IUEventType.java b/java/src/ipaaca/IUEventType.java index 9b618c610fcb43f026dba45468de15288e7e0ee5..efb2b1b419623883dbcf2a0ebacf1ee33b28096c 100644 --- a/java/src/ipaaca/IUEventType.java +++ b/java/src/ipaaca/IUEventType.java @@ -1,5 +1,6 @@ package ipaaca; -public enum IUEventType { - ADDED, COMMITTED, DELETED, RETRACTED, UPDATED,LINKSUPDATED; +public enum IUEventType +{ + ADDED, COMMITTED, DELETED, RETRACTED, UPDATED, LINKSUPDATED; } diff --git a/java/src/ipaaca/IUPublishedException.java b/java/src/ipaaca/IUPublishedException.java index 0431e1dae1f830f5a9f9f68d2d40cc405e43e532..ee8bc46cecbac08d33df742ea4ca7837e779df6d 100644 --- a/java/src/ipaaca/IUPublishedException.java +++ b/java/src/ipaaca/IUPublishedException.java @@ -1,17 +1,24 @@ package ipaaca; -public class IUPublishedException extends RuntimeException{ - private static final long serialVersionUID = 1L; - private final AbstractIU iu; - - public AbstractIU getIU() { - return iu; - } - - public IUPublishedException(AbstractIU iu) - { - super("IU " + iu.getUid() + " is already present in the output buffer."); - this.iu = iu; - } +/** + * IUPublishedException exceptions occur when publishing (=putting it in an output buffer) an already published IU. + * @author hvanwelbergen + * + */ +public class IUPublishedException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + private final AbstractIU iu; + + public AbstractIU getIU() + { + return iu; + } + + public IUPublishedException(AbstractIU iu) + { + super("IU " + iu.getUid() + " is already present in the output buffer."); + this.iu = iu; + } } diff --git a/java/src/ipaaca/IUReadOnlyException.java b/java/src/ipaaca/IUReadOnlyException.java index 59bf6a293cba54b3718a81a9926ebe4e7f95ee5a..6218d376b7c6cfd3d01bbe22dbd45c31ff554a9b 100644 --- a/java/src/ipaaca/IUReadOnlyException.java +++ b/java/src/ipaaca/IUReadOnlyException.java @@ -1,16 +1,23 @@ package ipaaca; -public class IUReadOnlyException extends RuntimeException{ - private static final long serialVersionUID = 1L; - private final AbstractIU iu; - - public AbstractIU getIU() { - return iu; - } - - public IUReadOnlyException(AbstractIU iu) - { - super("Writing to IU " + iu.getUid() + " failed -- it is read-only."); - this.iu = iu; - } +/** + * IUReadOnlyException's occur when writing to a read-only IU + * @author hvanwelbergen + * + */ +public class IUReadOnlyException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + private final AbstractIU iu; + + public AbstractIU getIU() + { + return iu; + } + + public IUReadOnlyException(AbstractIU iu) + { + super("Writing to IU " + iu.getUid() + " failed -- it is read-only."); + this.iu = iu; + } } diff --git a/java/src/ipaaca/IUStore.java b/java/src/ipaaca/IUStore.java index 96b6d65899b8ffbfbb19443dbe5baaf9acf35adf..170b283938379bf71355557fd9ef24b7c9b16014 100644 --- a/java/src/ipaaca/IUStore.java +++ b/java/src/ipaaca/IUStore.java @@ -1,7 +1,14 @@ package ipaaca; -import java.util.HashMap; +import java.util.HashMap; -public class IUStore<X extends AbstractIU> extends HashMap<String,X>{ +/** + * An IUStore maps an IUid to an IU + * @author hvanwelbergen + * + * @param <X> type of AbstractIU stored in the store + */ +public class IUStore<X extends AbstractIU> extends HashMap<String, X> +{ private static final long serialVersionUID = 1L; } diff --git a/java/src/ipaaca/IUUpdateFailedException.java b/java/src/ipaaca/IUUpdateFailedException.java index e06c1d9e1f0df44a9a993477e3fdf8af67b294d5..d756efa5bd4e288a69a986297a0d9549561e5a1b 100644 --- a/java/src/ipaaca/IUUpdateFailedException.java +++ b/java/src/ipaaca/IUUpdateFailedException.java @@ -1,16 +1,23 @@ package ipaaca; -public class IUUpdateFailedException extends RuntimeException{ - private static final long serialVersionUID = 1L; - private final AbstractIU iu; - - public AbstractIU getIU() { - return iu; - } - - public IUUpdateFailedException(AbstractIU iu) - { - super("Remote update failed for IU " + iu.getUid() + "."); - this.iu = iu; - } +/** + * Indicates that a remote update failed + * @author hvanwelbergen + * + */ +public class IUUpdateFailedException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + private final AbstractIU iu; + + public AbstractIU getIU() + { + return iu; + } + + public IUUpdateFailedException(AbstractIU iu) + { + super("Remote update failed for IU " + iu.getUid() + "."); + this.iu = iu; + } } diff --git a/java/src/ipaaca/Initializer.java b/java/src/ipaaca/Initializer.java index 331bdcc7ed5df44a3e4e85561e605917a1116594..815fb8e4381e254bbcd5fb92035f89f1c2239245 100644 --- a/java/src/ipaaca/Initializer.java +++ b/java/src/ipaaca/Initializer.java @@ -5,35 +5,29 @@ import rsb.converter.ConverterSignature; import rsb.converter.DefaultConverterRepository; import rsb.converter.ProtocolBufferConverter; -public final class Initializer { -// def initialize_ipaaca_rsb():#{{{ -// rsb.transport.converter.registerGlobalConverter( -// IntConverter(wireSchema="int32", dataType=int)) -// rsb.transport.converter.registerGlobalConverter( -// IUConverter(wireSchema="ipaaca-iu", dataType=IU)) -// rsb.transport.converter.registerGlobalConverter( -// IUPayloadUpdateConverter( -// wireSchema="ipaaca-iu-payload-update", -// dataType=IUPayloadUpdate)) -// rsb.transport.converter.registerGlobalConverter( -// rsb.transport.converter.ProtocolBufferConverter( -// messageClass=iuProtoBuf_pb2.IUCommission)) -// rsb.__defaultParticipantConfig = rsb.ParticipantConfig.fromDefaultSources() -// #}}} - public static void initializeIpaacaRsb() - { - DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter()); - DefaultConverterRepository.getDefaultConverterRepository() - .addConverter(new ProtocolBufferConverter<IUCommission>(IUCommission.getDefaultInstance())); - - DefaultConverterRepository.getDefaultConverterRepository().addConverter( - new IUConverter(new ConverterSignature("ipaaca-iu", RemotePushIU.class))); - DefaultConverterRepository.getDefaultConverterRepository().addConverter( +/** + * Hooks up the ipaaca converters, call initializeIpaacaRsb() before using ipaaca. + * @author hvanwelbergen + * + */ +public final class Initializer +{ + private Initializer() + { + } + + public static void initializeIpaacaRsb() + { + DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter()); + DefaultConverterRepository.getDefaultConverterRepository().addConverter( + new ProtocolBufferConverter<IUCommission>(IUCommission.getDefaultInstance())); + + DefaultConverterRepository.getDefaultConverterRepository().addConverter( + new IUConverter(new ConverterSignature("ipaaca-iu", RemotePushIU.class))); + DefaultConverterRepository.getDefaultConverterRepository().addConverter( new IUConverter(new ConverterSignature("ipaaca-localiu", LocalIU.class))); - DefaultConverterRepository.getDefaultConverterRepository().addConverter( - new PayloadConverter()); - DefaultConverterRepository.getDefaultConverterRepository().addConverter( - new LinkUpdateConverter()); - - } + DefaultConverterRepository.getDefaultConverterRepository().addConverter(new PayloadConverter()); + DefaultConverterRepository.getDefaultConverterRepository().addConverter(new LinkUpdateConverter()); + + } } diff --git a/java/src/ipaaca/InputBuffer.java b/java/src/ipaaca/InputBuffer.java index 961785a29501e2e4bd5b3e6dfc03c4d84f2377e6..b9f195019ae8cc849eb7a156bafd976741bc35b4 100644 --- a/java/src/ipaaca/InputBuffer.java +++ b/java/src/ipaaca/InputBuffer.java @@ -25,68 +25,69 @@ import rsb.patterns.RemoteServer; * An InputBuffer that holds remote IUs. * @author hvanwelbergen */ -public class InputBuffer extends Buffer{ - private Map<String,RemoteServer> remoteServerStore = new HashMap<String,RemoteServer>(); - private Map<String,Listener> listenerStore = new HashMap<String,Listener>(); - private Set<String> categoryInterests = new HashSet<String>(); - private final static Logger logger = LoggerFactory.getLogger(InputBuffer.class.getName()); - private IUStore<RemotePushIU> iuStore = new IUStore<RemotePushIU>(); - - public void close() - { - for(Listener listener: listenerStore.values()) - { - listener.deactivate(); - } - for(RemoteServer remServer: remoteServerStore.values()) - { - remServer.deactivate(); - } - } - -// def __init__(self, owning_component_name, category_interests=None, participant_config=None): -// '''Create an InputBuffer. -// -// Keyword arguments: -// owning_compontent_name -- name of the entity that owns this InputBuffer -// category_interests -- list of IU categories this Buffer is interested in -// participant_config = RSB configuration -// ''' -// super(InputBuffer, self).__init__(owning_component_name, participant_config) -// self._unique_name = '/ipaaca/component/'+str(owning_component_name)+'ID'+self._uuid+'/IB' -// self._listener_store = {} # one per IU category -// self._remote_server_store = {} # one per remote-IU-owning Component -// self._category_interests = [] -// if category_interests is not None: -// for cat in category_interests: -// self._create_category_listener_if_needed(cat) - public InputBuffer(String owningComponentName, Set<String>categoryInterests) - { - super(owningComponentName); - uniqueName = "/ipaaca/component/"+ owningComponentName +"ID"+uuid+"/IB"; - - for (String cat:categoryInterests) - { - createCategoryListenerIfNeeded(cat); - } - } - -// def _get_remote_server(self, iu): -// '''Return (or create, store and return) a remote server.''' -// if iu.owner_name in self._remote_server_store: -// return self._remote_server_store[iu.owner_name] -// remote_server = rsb.createRemoteServer(rsb.Scope(str(iu.owner_name))) -// self._remote_server_store[iu.owner_name] = remote_server -// return remote_server - public RemoteServer getRemoteServer(AbstractIU iu) - { - if(remoteServerStore.containsKey(iu.getOwnerName())) - { - return remoteServerStore.get(iu.getOwnerName()); - } - logger.debug("Getting remote server for {}",iu.getOwnerName()); - RemoteServer remoteServer = Factory.getInstance().createRemoteServer(new Scope(iu.getOwnerName())); - try +public class InputBuffer extends Buffer +{ + private Map<String, RemoteServer> remoteServerStore = new HashMap<String, RemoteServer>(); + private Map<String, Listener> listenerStore = new HashMap<String, Listener>(); + private Set<String> categoryInterests = new HashSet<String>(); + private final static Logger logger = LoggerFactory.getLogger(InputBuffer.class.getName()); + private IUStore<RemotePushIU> iuStore = new IUStore<RemotePushIU>(); + + public void close() + { + for (Listener listener : listenerStore.values()) + { + listener.deactivate(); + } + for (RemoteServer remServer : remoteServerStore.values()) + { + remServer.deactivate(); + } + } + + // def __init__(self, owning_component_name, category_interests=None, participant_config=None): + // '''Create an InputBuffer. + // + // Keyword arguments: + // owning_compontent_name -- name of the entity that owns this InputBuffer + // category_interests -- list of IU categories this Buffer is interested in + // participant_config = RSB configuration + // ''' + // super(InputBuffer, self).__init__(owning_component_name, participant_config) + // self._unique_name = '/ipaaca/component/'+str(owning_component_name)+'ID'+self._uuid+'/IB' + // self._listener_store = {} # one per IU category + // self._remote_server_store = {} # one per remote-IU-owning Component + // self._category_interests = [] + // if category_interests is not None: + // for cat in category_interests: + // self._create_category_listener_if_needed(cat) + public InputBuffer(String owningComponentName, Set<String> categoryInterests) + { + super(owningComponentName); + uniqueName = "/ipaaca/component/" + owningComponentName + "ID" + uuid + "/IB"; + + for (String cat : categoryInterests) + { + createCategoryListenerIfNeeded(cat); + } + } + + // def _get_remote_server(self, iu): + // '''Return (or create, store and return) a remote server.''' + // if iu.owner_name in self._remote_server_store: + // return self._remote_server_store[iu.owner_name] + // remote_server = rsb.createRemoteServer(rsb.Scope(str(iu.owner_name))) + // self._remote_server_store[iu.owner_name] = remote_server + // return remote_server + public RemoteServer getRemoteServer(AbstractIU iu) + { + if (remoteServerStore.containsKey(iu.getOwnerName())) + { + return remoteServerStore.get(iu.getOwnerName()); + } + logger.debug("Getting remote server for {}", iu.getOwnerName()); + RemoteServer remoteServer = Factory.getInstance().createRemoteServer(new Scope(iu.getOwnerName())); + try { remoteServer.activate(); } @@ -94,183 +95,186 @@ public class InputBuffer extends Buffer{ { throw new RuntimeException(e); } - remoteServerStore.put(iu.getOwnerName(), remoteServer); - return remoteServer; - } - -// def _create_category_listener_if_needed(self, iu_category): -// '''Return (or create, store and return) a category listener.''' -// if iu_category in self._listener_store: return self._informer_store[iu_category] -// cat_listener = rsb.createListener(rsb.Scope("/ipaaca/category/"+str(iu_category)), config=self._participant_config) -// cat_listener.addHandler(self._handle_iu_events) -// self._listener_store[iu_category] = cat_listener -// self._category_interests.append(iu_category) -// logger.info("Added category listener for "+iu_category) -// return cat_listener - private Listener createCategoryListenerIfNeeded(String category) - { - if(listenerStore.containsKey(category)) - { - return listenerStore.get(category); - } - Listener listener = Factory.getInstance().createListener(new Scope("/ipaaca/category/"+category)); - listenerStore.put(category,listener); - categoryInterests.add(category); - listener.addHandler(new InputHandler(), true); - logger.info("Added category listener for {}",category); - try + remoteServerStore.put(iu.getOwnerName(), remoteServer); + return remoteServer; + } + + // def _create_category_listener_if_needed(self, iu_category): + // '''Return (or create, store and return) a category listener.''' + // if iu_category in self._listener_store: return self._informer_store[iu_category] + // cat_listener = rsb.createListener(rsb.Scope("/ipaaca/category/"+str(iu_category)), config=self._participant_config) + // cat_listener.addHandler(self._handle_iu_events) + // self._listener_store[iu_category] = cat_listener + // self._category_interests.append(iu_category) + // logger.info("Added category listener for "+iu_category) + // return cat_listener + private Listener createCategoryListenerIfNeeded(String category) + { + if (listenerStore.containsKey(category)) + { + return listenerStore.get(category); + } + Listener listener = Factory.getInstance().createListener(new Scope("/ipaaca/category/" + category)); + listenerStore.put(category, listener); + categoryInterests.add(category); + listener.addHandler(new InputHandler(), true); + logger.info("Added category listener for {}", category); + try { listener.activate(); } catch (InitializeException e) { throw new RuntimeException(e); - } - return listener; - } - - class InputHandler implements Handler - { + } + return listener; + } - @Override - public void internalNotify(Event ev) { - handleIUEvents(ev); - } - - } -// def _handle_iu_events(self, event): -// '''Dispatch incoming IU events. -// -// Adds incoming IU's to the store, applies payload and commit updates to -// IU, calls IU event handlers.' -// -// Keyword arguments: -// event -- a converted RSB event -// ''' -// if type(event.data) is RemotePushIU: -// # a new IU -// if event.data.uid in self._iu_store: -// # already in our store -// pass -// else: -// self._iu_store[ event.data.uid ] = event.data -// event.data.buffer = self -// self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.ADDED, category=event.data.category) -// else: -// # an update to an existing IU -// if event.data.writer_name == self.unique_name: -// # Discard updates that originate from this buffer -// return -// if event.data.uid not in self._iu_store: -// # TODO: we should request the IU's owner to send us the IU -// logger.warning("Update message for IU which we did not fully receive before.") -// return -// if type(event.data) is iuProtoBuf_pb2.IUCommission: -// # IU commit -// iu = self._iu_store[event.data.uid] -// iu._apply_commission() -// iu._revision = event.data.revision -// self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.COMMITTED, category=iu.category) -// elif type(event.data) is IUPayloadUpdate: -// # IU payload update -// iu = self._iu_store[event.data.uid] -// iu._apply_update(event.data) -// self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.UPDATED, category=iu.category) - /** - * Dispatch incoming IU events. - */ - private void handleIUEvents(Event event) - { - if(event.getData() instanceof RemotePushIU) - { - RemotePushIU rp = (RemotePushIU)event.getData(); - //a new IU - if(iuStore.containsKey(rp.getUid())) - { - // already in our store - return; - } - else - { - iuStore.put(rp.getUid(), rp); - rp.setBuffer(this); - this.callIuEventHandlers(rp.getUid(), false, IUEventType.ADDED, rp.getCategory()); - } - } - else - { - if (event.getData() instanceof IULinkUpdate) + class InputHandler implements Handler + { + + @Override + public void internalNotify(Event ev) + { + handleIUEvents(ev); + } + + } + + // def _handle_iu_events(self, event): + // '''Dispatch incoming IU events. + // + // Adds incoming IU's to the store, applies payload and commit updates to + // IU, calls IU event handlers.' + // + // Keyword arguments: + // event -- a converted RSB event + // ''' + // if type(event.data) is RemotePushIU: + // # a new IU + // if event.data.uid in self._iu_store: + // # already in our store + // pass + // else: + // self._iu_store[ event.data.uid ] = event.data + // event.data.buffer = self + // self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.ADDED, category=event.data.category) + // else: + // # an update to an existing IU + // if event.data.writer_name == self.unique_name: + // # Discard updates that originate from this buffer + // return + // if event.data.uid not in self._iu_store: + // # TODO: we should request the IU's owner to send us the IU + // logger.warning("Update message for IU which we did not fully receive before.") + // return + // if type(event.data) is iuProtoBuf_pb2.IUCommission: + // # IU commit + // iu = self._iu_store[event.data.uid] + // iu._apply_commission() + // iu._revision = event.data.revision + // self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.COMMITTED, category=iu.category) + // elif type(event.data) is IUPayloadUpdate: + // # IU payload update + // iu = self._iu_store[event.data.uid] + // iu._apply_update(event.data) + // self.call_iu_event_handlers(event.data.uid, local=False, event_type=IUEventType.UPDATED, category=iu.category) + /** + * Dispatch incoming IU events. + */ + private void handleIUEvents(Event event) + { + if (event.getData() instanceof RemotePushIU) + { + RemotePushIU rp = (RemotePushIU) event.getData(); + // a new IU + if (iuStore.containsKey(rp.getUid())) + { + // already in our store + return; + } + else + { + iuStore.put(rp.getUid(), rp); + rp.setBuffer(this); + this.callIuEventHandlers(rp.getUid(), false, IUEventType.ADDED, rp.getCategory()); + } + } + else + { + if (event.getData() instanceof IULinkUpdate) { - IULinkUpdate iuLinkUpdate = (IULinkUpdate)event.getData(); - if(iuLinkUpdate.getWriterName().equals(this.getUniqueName())) + IULinkUpdate iuLinkUpdate = (IULinkUpdate) event.getData(); + if (iuLinkUpdate.getWriterName().equals(this.getUniqueName())) { - //Discard updates that originate from this buffer + // Discard updates that originate from this buffer return; } - if(!iuStore.containsKey(iuLinkUpdate.getUid())) + if (!iuStore.containsKey(iuLinkUpdate.getUid())) { logger.warn("Link update message for IU which we did not fully receive before."); return; } - RemotePushIU iu = this.iuStore.get(iuLinkUpdate.getUid()); + RemotePushIU iu = this.iuStore.get(iuLinkUpdate.getUid()); iu.applyLinkUpdate(iuLinkUpdate); callIuEventHandlers(iu.getUid(), false, IUEventType.LINKSUPDATED, iu.category); } - if (event.getData() instanceof IUPayloadUpdate) - { - IUPayloadUpdate iuUpdate = (IUPayloadUpdate)event.getData(); - logger.debug("handleIUEvents invoked with an IUPayloadUpdate: {}", iuUpdate); - if(iuUpdate.getWriterName().equals(this.getUniqueName())) - { - //Discard updates that originate from this buffer - return; - } - if(!iuStore.containsKey(iuUpdate.getUid())) - { - logger.warn("Update message for IU which we did not fully receive before."); - return; - } - RemotePushIU iu = this.iuStore.get(iuUpdate.getUid()); - iu.applyUpdate(iuUpdate); - callIuEventHandlers(iu.getUid(), false, IUEventType.UPDATED, iu.category); - } - if (event.getData() instanceof IUCommission) - { - IUCommission iuc = (IUCommission)event.getData(); - logger.debug("handleIUEvents invoked with an IUCommission: {}", iuc); - logger.debug("{}, {}",iuc.getWriterName(), this.getUniqueName()); - - if(iuc.getWriterName().equals(this.getUniqueName())) - { - //Discard updates that originate from this buffer - return; - } - if(!iuStore.containsKey(iuc.getUid())) - { - logger.warn("Update message for IU which we did not fully receive before."); - return; - } - RemotePushIU iu = this.iuStore.get(iuc.getUid()); - iu.applyCommmision(); - iu.setRevision(iuc.getRevision()); - callIuEventHandlers(iuc.getUid(), false, IUEventType.COMMITTED, iu.getCategory()); - } - } - } - - public InputBuffer(String owningComponentName) { - super(owningComponentName); - } + if (event.getData() instanceof IUPayloadUpdate) + { + IUPayloadUpdate iuUpdate = (IUPayloadUpdate) event.getData(); + logger.debug("handleIUEvents invoked with an IUPayloadUpdate: {}", iuUpdate); + if (iuUpdate.getWriterName().equals(this.getUniqueName())) + { + // Discard updates that originate from this buffer + return; + } + if (!iuStore.containsKey(iuUpdate.getUid())) + { + logger.warn("Update message for IU which we did not fully receive before."); + return; + } + RemotePushIU iu = this.iuStore.get(iuUpdate.getUid()); + iu.applyUpdate(iuUpdate); + callIuEventHandlers(iu.getUid(), false, IUEventType.UPDATED, iu.category); + } + if (event.getData() instanceof IUCommission) + { + IUCommission iuc = (IUCommission) event.getData(); + logger.debug("handleIUEvents invoked with an IUCommission: {}", iuc); + logger.debug("{}, {}", iuc.getWriterName(), this.getUniqueName()); + + if (iuc.getWriterName().equals(this.getUniqueName())) + { + // Discard updates that originate from this buffer + return; + } + if (!iuStore.containsKey(iuc.getUid())) + { + logger.warn("Update message for IU which we did not fully receive before."); + return; + } + RemotePushIU iu = this.iuStore.get(iuc.getUid()); + iu.applyCommmision(); + iu.setRevision(iuc.getRevision()); + callIuEventHandlers(iuc.getUid(), false, IUEventType.COMMITTED, iu.getCategory()); + } + } + } + + public InputBuffer(String owningComponentName) + { + super(owningComponentName); + } @Override public AbstractIU getIU(String iuid) { return iuStore.get(iuid); } - - public Collection<RemotePushIU> getIUs() - { - return iuStore.values(); - } + + public Collection<RemotePushIU> getIUs() + { + return iuStore.values(); + } } diff --git a/java/src/ipaaca/IntConverter.java b/java/src/ipaaca/IntConverter.java index 2c7fba3a79b20731f68f7c6761f5aa214d8e19f3..9ca0c6012318d481d6797be06b177ac7129a3b68 100644 --- a/java/src/ipaaca/IntConverter.java +++ b/java/src/ipaaca/IntConverter.java @@ -11,25 +11,27 @@ import rsb.converter.WireContents; import com.google.protobuf.InvalidProtocolBufferException; +/** + * Serializer/deserializer for ints + * @author hvanwelbergen + * + */ public class IntConverter implements Converter<ByteBuffer> { - - + @Override public ConverterSignature getSignature() { - return new ConverterSignature("int32",Integer.class); + return new ConverterSignature("int32", Integer.class); } @Override public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException { - Integer intVal = (Integer)obj; - IntMessage message = IntMessage.newBuilder() - .setValue(intVal) - .build(); - - return new WireContents<ByteBuffer>(ByteBuffer.wrap(message.toByteArray()),"int32"); + Integer intVal = (Integer) obj; + IntMessage message = IntMessage.newBuilder().setValue(intVal).build(); + + return new WireContents<ByteBuffer>(ByteBuffer.wrap(message.toByteArray()), "int32"); } @Override diff --git a/java/src/ipaaca/LinkUpdateConverter.java b/java/src/ipaaca/LinkUpdateConverter.java index db85edb589f192c7bcb0a90d8f9d0e8c71896567..3351d8c473b5c971992ee28c4a11f9cfa5da758a 100644 --- a/java/src/ipaaca/LinkUpdateConverter.java +++ b/java/src/ipaaca/LinkUpdateConverter.java @@ -12,6 +12,11 @@ import rsb.converter.WireContents; import com.google.protobuf.InvalidProtocolBufferException; +/** + * Serializer/deserializer for IULinkUpdate + * @author hvanwelbergen + * + */ public class LinkUpdateConverter implements Converter<ByteBuffer> { private static final String LINKUPDATE_WIRESCHEMA = "ipaaca-iu-link-update"; @@ -28,20 +33,20 @@ public class LinkUpdateConverter implements Converter<ByteBuffer> { throw new RuntimeException(e); } - return new UserData<IULinkUpdate>(pl, IULinkUpdate.class); + return new UserData<IULinkUpdate>(pl, IULinkUpdate.class); } @Override public ConverterSignature getSignature() { - return new ConverterSignature(LINKUPDATE_WIRESCHEMA,IULinkUpdate.class); + return new ConverterSignature(LINKUPDATE_WIRESCHEMA, IULinkUpdate.class); } @Override public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException { - IULinkUpdate pl = (IULinkUpdate)obj; - return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),LINKUPDATE_WIRESCHEMA); + IULinkUpdate pl = (IULinkUpdate) obj; + return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()), LINKUPDATE_WIRESCHEMA); } } diff --git a/java/src/ipaaca/LocalIU.java b/java/src/ipaaca/LocalIU.java index 6abb71b824c65bff5ccedbeffee963b4df001369..e971a9c7bfd2f4a5a511f1989a8fa60dda514c6f 100644 --- a/java/src/ipaaca/LocalIU.java +++ b/java/src/ipaaca/LocalIU.java @@ -70,9 +70,9 @@ public class LocalIU extends AbstractIU { increaseRevisionNumber(); committed = true; - if(outputBuffer!=null) - { - outputBuffer.sendIUCommission(this, writerName); + if (outputBuffer != null) + { + outputBuffer.sendIUCommission(this, writerName); } } } @@ -112,7 +112,7 @@ public class LocalIU extends AbstractIU synchronized (revisionLock) { increaseRevisionNumber(); - if(isPublished()) + if (isPublished()) { String wName = null; if (getBuffer() != null) @@ -127,24 +127,19 @@ public class LocalIU extends AbstractIU { wName = null; } - Set<LinkSet> addSet = new HashSet<LinkSet>(); - for(Entry<String, Collection<String>> entry :linksToAdd.asMap().entrySet()) + Set<LinkSet> addSet = new HashSet<LinkSet>(); + for (Entry<String, Collection<String>> entry : linksToAdd.asMap().entrySet()) { addSet.add(LinkSet.newBuilder().setType(entry.getKey()).addAllTargets(entry.getValue()).build()); } - Set<LinkSet> removeSet = new HashSet<LinkSet>(); - for(Entry<String, Collection<String>> entry :linksToRemove.asMap().entrySet()) + Set<LinkSet> removeSet = new HashSet<LinkSet>(); + for (Entry<String, Collection<String>> entry : linksToRemove.asMap().entrySet()) { removeSet.add(LinkSet.newBuilder().setType(entry.getKey()).addAllTargets(entry.getValue()).build()); } - outputBuffer.sendIULinkUpdate(this,IULinkUpdate.newBuilder() - .setUid(getUid()) - .setRevision(getRevision()) - .setWriterName(wName) - .setIsDelta(isDelta) - .addAllNewLinks(addSet) - .addAllLinksToRemove(removeSet) - .build()); + outputBuffer.sendIULinkUpdate(this, + IULinkUpdate.newBuilder().setUid(getUid()).setRevision(getRevision()).setWriterName(wName).setIsDelta(isDelta) + .addAllNewLinks(addSet).addAllLinksToRemove(removeSet).build()); } } } diff --git a/java/src/ipaaca/Payload.java b/java/src/ipaaca/Payload.java index 77d6ec10550db8f439a3668f1d40d1cd30f7696e..c2e3a93604a3e68817c3615c20bcc032318a4e85 100644 --- a/java/src/ipaaca/Payload.java +++ b/java/src/ipaaca/Payload.java @@ -22,7 +22,7 @@ public class Payload implements Map<String, String> { this.iu = iu; } - + // def __init__(self, remote_push_iu, new_payload): // """Create remote payload object. // @@ -34,46 +34,46 @@ public class Payload implements Map<String, String> // self._remote_push_iu = remote_push_iu // if new_payload is not None: // for k,v in new_payload.items(): - // dict.__setitem__(self, k, v) + // dict.__setitem__(self, k, v) public Payload(AbstractIU iu, List<PayloadItem> payloadItems) { - this(iu,payloadItems,null); + this(iu, payloadItems, null); } - - public Payload(AbstractIU iu, Map<String,String> newPayload) + + public Payload(AbstractIU iu, Map<String, String> newPayload) { - this(iu,newPayload,null); + this(iu, newPayload, null); } - - public Payload(AbstractIU iu, Map<String,String> newPayload, String writerName) + + public Payload(AbstractIU iu, Map<String, String> newPayload, String writerName) { this.iu = iu; set(newPayload, writerName); } - - public Payload(AbstractIU iu, List<PayloadItem>newPayload, String writerName) + + public Payload(AbstractIU iu, List<PayloadItem> newPayload, String writerName) { this.iu = iu; - set(newPayload,writerName); + set(newPayload, writerName); } - - public void set(Map<String,String> newPayload, String writerName) + + public void set(Map<String, String> newPayload, String writerName) { iu.setPayload(newPayload, writerName); map.clear(); map.putAll(newPayload); } - - public void set(List<PayloadItem>newPayload, String writerName) + + public void set(List<PayloadItem> newPayload, String writerName) { - iu.handlePayloadSetting(newPayload,writerName); + iu.handlePayloadSetting(newPayload, writerName); map.clear(); for (PayloadItem item : newPayload) { map.put(item.getKey(), item.getValue()); } } - + // def _remotely_enforced_setitem(self, k, v): // """Sets an item when requested remotely.""" // return dict.__setitem__(self, k, v) @@ -160,7 +160,7 @@ public class Payload implements Map<String, String> // raise IUUpdateFailedError(self._remote_push_iu) // else: // self._remote_push_iu._revision = new_revision - // dict.__setitem__(self, k, v) + // dict.__setitem__(self, k, v) /** * Set item in this payload. * Requests item setting from the OutputBuffer holding the local version @@ -204,7 +204,7 @@ public class Payload implements Map<String, String> * Requests item deletion from the OutputBuffer holding the local version * of this IU. Returns when permission is granted and item is deleted; * otherwise raises an IUUpdateFailedError. - */ + */ public String remove(Object key, String writer) { iu.removeFromPayload(key, writer); diff --git a/java/src/ipaaca/PayloadConverter.java b/java/src/ipaaca/PayloadConverter.java index a95e7110080722ec36007713ee3ad802713cfb74..c07993fa074f6fef846a6c8270984b9c251898a0 100644 --- a/java/src/ipaaca/PayloadConverter.java +++ b/java/src/ipaaca/PayloadConverter.java @@ -12,6 +12,11 @@ import rsb.converter.WireContents; import com.google.protobuf.InvalidProtocolBufferException; +/** + * Serializer/deserializer for IUPayloadUpdate + * @author hvanwelbergen + * + */ public class PayloadConverter implements Converter<ByteBuffer> { private static final String PAYLOAD_WIRESCHEMA = "ipaaca-iu-payload-update"; @@ -28,20 +33,20 @@ public class PayloadConverter implements Converter<ByteBuffer> { throw new RuntimeException(e); } - return new UserData<IUPayloadUpdate>(pl, IUPayloadUpdate.class); + return new UserData<IUPayloadUpdate>(pl, IUPayloadUpdate.class); } @Override public ConverterSignature getSignature() { - return new ConverterSignature(PAYLOAD_WIRESCHEMA,IUPayloadUpdate.class); + return new ConverterSignature(PAYLOAD_WIRESCHEMA, IUPayloadUpdate.class); } @Override public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException { - IUPayloadUpdate pl = (IUPayloadUpdate)obj; - return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),PAYLOAD_WIRESCHEMA); + IUPayloadUpdate pl = (IUPayloadUpdate) obj; + return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()), PAYLOAD_WIRESCHEMA); } } diff --git a/java/src/ipaacademo/PythonCall.java b/java/src/ipaacademo/PythonCall.java index 09c709343b97b30016d3d310953cd2bd606400fa..6aca5d77a98710ee4a56eab080a06c740b640b95 100644 --- a/java/src/ipaacademo/PythonCall.java +++ b/java/src/ipaacademo/PythonCall.java @@ -6,6 +6,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +/** + * Demonstrates how to call a python script from java + * @author hvanwelbergen + * + */ public class PythonCall { diff --git a/java/test/src/ipaaca/InputBufferTest.java b/java/test/src/ipaaca/InputBufferTest.java index ad12fc61261611ca11f44382f906ca7450e65459..aa63e9833ab05e2a8180253284a91fcf94b914c2 100644 --- a/java/test/src/ipaaca/InputBufferTest.java +++ b/java/test/src/ipaaca/InputBufferTest.java @@ -14,6 +14,11 @@ import rsb.RSBException; import com.google.common.collect.ImmutableSet; +/** + * Unit testcases for the input buffer + * @author hvanwelbergen + * + */ public class InputBufferTest { private static final String COMPID = "Comp1"; diff --git a/java/test/src/ipaaca/IuConverterTest.java b/java/test/src/ipaaca/IuConverterTest.java index d1b558ff0bc0191da401c37ea6975dfba98949e4..4d1fac894ee8de350d03bd01d118633e55f7ad63 100644 --- a/java/test/src/ipaaca/IuConverterTest.java +++ b/java/test/src/ipaaca/IuConverterTest.java @@ -27,6 +27,11 @@ import rsb.converter.WireContents; import rsb.patterns.RemoteServer; import static ipaaca.IUTestUtil.*; +/** + * Unit test cases for the IUConverter + * @author hvanwelbergen + * + */ public class IuConverterTest { private static final String CATEGORY = "category1"; diff --git a/java/test/src/ipaaca/LocalIUTest.java b/java/test/src/ipaaca/LocalIUTest.java index f131997e69b4359a9b8d2951d9e98a085fac8a56..797859be6bf1b4683eba7f27cc19d57440c3ff8c 100644 --- a/java/test/src/ipaaca/LocalIUTest.java +++ b/java/test/src/ipaaca/LocalIUTest.java @@ -6,7 +6,10 @@ import ipaaca.protobuf.Ipaaca.IUPayloadUpdate; import org.junit.Before; import org.junit.Test; import static org.mockito.Mockito.*; - +/** + * Unit testcases for the LocalIU + * @author hvanwelbergen + */ public class LocalIUTest { OutputBuffer mockBuffer = mock(OutputBuffer.class); diff --git a/python/build.properties b/python/build.properties index aa9003a9c77f1ce8614fe43a382b09d6778c25ab..fba546ac8220446b170b2f6fdfa294f84bd8be02 100644 --- a/python/build.properties +++ b/python/build.properties @@ -4,4 +4,5 @@ resource.path=${shared.resources}/Shared3DModels/resource;${shared.resources}/De rebuild.list= pyzip.excludes= run.py=run.py +publish.resolver=soa.core.repository diff --git a/python/build.xml b/python/build.xml index 2c571af2bc17e9bc76328646e3960baf3a756d15..f24e48505d48491e5c3ea0333c79e60f098096e4 100644 --- a/python/build.xml +++ b/python/build.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project name="IpaacaPython" default="run"> - <import file="../../soashared/ant/build.xml" /> + <!--import file="../../soashared/ant/build.xml" /--> + <import file="../../HmiBuild/build.xml" /> <target name="-pre-compilation"> <echo message="Compiling protobuf file" /> <exec executable="protoc"> diff --git a/python/ivy.xml b/python/ivy.xml index b24cc6a006dbef42152a7da7e37b10ddfed0ad81..9eb98898c4d5a552bd530ee05c39b90c9d942350 100644 --- a/python/ivy.xml +++ b/python/ivy.xml @@ -1,7 +1,11 @@ <ivy-module version="2.0"> <info organisation="ipaaca" module="IpaacaPython" /> + <publications> + <artifact type="zip" ext="zip"/> + </publications> <dependencies> <dependency org="google" name="protobuf" rev="latest.release"/> <dependency org="rsb" name="rsb" rev="latest.release"/> </dependencies> + </ivy-module> diff --git a/python/src/ipaaca.py b/python/src/ipaaca.py index 602243d0effb42ce6a6fa727a8a6d0649984b490..af8f3f5ce953956297b70f577998c6a03775ee62 100755 --- a/python/src/ipaaca.py +++ b/python/src/ipaaca.py @@ -851,7 +851,7 @@ class InputBuffer(Buffer): self._category_interests = [] if category_interests is not None: for cat in category_interests: - self._create_category_listener_if_needed(cat) + self._add_category_listener(cat) def _get_remote_server(self, iu): '''Return (or create, store and return) a remote server.''' @@ -862,15 +862,14 @@ class InputBuffer(Buffer): self._remote_server_store[iu.owner_name] = remote_server return remote_server - def _create_category_listener_if_needed(self, iu_category): + def _add_category_listener(self, iu_category): '''Return (or create, store and return) a category listener.''' - if iu_category in self._listener_store: return self._informer_store[iu_category] - cat_listener = rsb.createListener(rsb.Scope("/ipaaca/category/"+str(iu_category)), config=self._participant_config) - cat_listener.addHandler(self._handle_iu_events) - self._listener_store[iu_category] = cat_listener - self._category_interests.append(iu_category) - logger.info("Added listener in scope "+"/ipaaca/category/"+iu_category) - return cat_listener + if iu_category not in self._listener_store: + cat_listener = rsb.createListener(rsb.Scope("/ipaaca/category/"+str(iu_category)), config=self._participant_config) + cat_listener.addHandler(self._handle_iu_events) + self._listener_store[iu_category] = cat_listener + self._category_interests.append(iu_category) + logger.info("Added listener in scope "+"/ipaaca/category/"+iu_category) def _handle_iu_events(self, event): '''Dispatch incoming IU events. @@ -919,6 +918,10 @@ class InputBuffer(Buffer): else: logger.warning('Warning: _handle_iu_events failed to handle an object of type '+str(type_)) + def add_category_interests(self, category_interests): + for interest in category_interests: + self._add_category_listener(interest) + class OutputBuffer(Buffer):