From 4553dd388b24fbc794f0d571dd9d75f5b95bc5a2 Mon Sep 17 00:00:00 2001 From: hvanwelbergen <hvanwelbergen@patty.TechFak.Uni-Bielefeld.DE> Date: Fri, 27 Apr 2012 13:31:53 +0200 Subject: [PATCH] Fixes some checkstyle formatting issues --- java/src/ipaaca/Buffer.java | 152 +++---- java/src/ipaaca/HandlerFunctor.java | 5 +- java/src/ipaaca/IUAccessMode.java | 5 +- java/src/ipaaca/IUCommittedException.java | 30 +- java/src/ipaaca/IUConverter.java | 52 +-- java/src/ipaaca/IUEventHandler.java | 146 ++++--- java/src/ipaaca/IUEventType.java | 5 +- java/src/ipaaca/IUPublishedException.java | 2 +- java/src/ipaaca/IUReadOnlyException.java | 2 +- java/src/ipaaca/IUUpdateFailedException.java | 2 +- java/src/ipaaca/Initializer.java | 7 +- java/src/ipaaca/InputBuffer.java | 436 ++++++++++--------- java/src/ipaaca/IntConverter.java | 17 +- java/src/ipaaca/LinkUpdateConverter.java | 10 +- java/src/ipaaca/LocalIU.java | 27 +- java/src/ipaaca/Payload.java | 38 +- java/src/ipaaca/PayloadConverter.java | 10 +- 17 files changed, 470 insertions(+), 476 deletions(-) diff --git a/java/src/ipaaca/Buffer.java b/java/src/ipaaca/Buffer.java index f2ea130..e335e1f 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 5f4edbd..4020b73 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 6562e01..0294131 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 dd079b5..9564de2 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 7b16418..5f3d46b 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 85f956f..25f2135 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 9b618c6..efb2b1b 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 d94d5dd..ee8bc46 100644 --- a/java/src/ipaaca/IUPublishedException.java +++ b/java/src/ipaaca/IUPublishedException.java @@ -3,7 +3,7 @@ package ipaaca; /** * IUPublishedException exceptions occur when publishing (=putting it in an output buffer) an already published IU. * @author hvanwelbergen - * + * */ public class IUPublishedException extends RuntimeException { diff --git a/java/src/ipaaca/IUReadOnlyException.java b/java/src/ipaaca/IUReadOnlyException.java index cc7b935..6218d37 100644 --- a/java/src/ipaaca/IUReadOnlyException.java +++ b/java/src/ipaaca/IUReadOnlyException.java @@ -3,7 +3,7 @@ package ipaaca; /** * IUReadOnlyException's occur when writing to a read-only IU * @author hvanwelbergen - * + * */ public class IUReadOnlyException extends RuntimeException { diff --git a/java/src/ipaaca/IUUpdateFailedException.java b/java/src/ipaaca/IUUpdateFailedException.java index e2b9b17..d756efa 100644 --- a/java/src/ipaaca/IUUpdateFailedException.java +++ b/java/src/ipaaca/IUUpdateFailedException.java @@ -3,7 +3,7 @@ package ipaaca; /** * Indicates that a remote update failed * @author hvanwelbergen - * + * */ public class IUUpdateFailedException extends RuntimeException { diff --git a/java/src/ipaaca/Initializer.java b/java/src/ipaaca/Initializer.java index 0695993..815fb8e 100644 --- a/java/src/ipaaca/Initializer.java +++ b/java/src/ipaaca/Initializer.java @@ -8,11 +8,14 @@ import rsb.converter.ProtocolBufferConverter; /** * Hooks up the ipaaca converters, call initializeIpaacaRsb() before using ipaaca. * @author hvanwelbergen - * + * */ public final class Initializer { - private Initializer(){} + private Initializer() + { + } + public static void initializeIpaacaRsb() { DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter()); diff --git a/java/src/ipaaca/InputBuffer.java b/java/src/ipaaca/InputBuffer.java index 961785a..b9f1950 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 1327b10..9ca0c60 100644 --- a/java/src/ipaaca/IntConverter.java +++ b/java/src/ipaaca/IntConverter.java @@ -14,27 +14,24 @@ 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 a61e0e4..3351d8c 100644 --- a/java/src/ipaaca/LinkUpdateConverter.java +++ b/java/src/ipaaca/LinkUpdateConverter.java @@ -15,7 +15,7 @@ import com.google.protobuf.InvalidProtocolBufferException; /** * Serializer/deserializer for IULinkUpdate * @author hvanwelbergen - * + * */ public class LinkUpdateConverter implements Converter<ByteBuffer> { @@ -33,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 6abb71b..e971a9c 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 77d6ec1..c2e3a93 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 c78546c..c07993f 100644 --- a/java/src/ipaaca/PayloadConverter.java +++ b/java/src/ipaaca/PayloadConverter.java @@ -15,7 +15,7 @@ import com.google.protobuf.InvalidProtocolBufferException; /** * Serializer/deserializer for IUPayloadUpdate * @author hvanwelbergen - * + * */ public class PayloadConverter implements Converter<ByteBuffer> { @@ -33,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); } } -- GitLab