[ohla-devel] SF.net SVN: ohla: [116] trunk/rti/src/java/net/sf/ohla/rti1516
Status: Beta
Brought to you by:
mnewcomb
From: <mne...@us...> - 2007-02-13 03:23:39
|
Revision: 116 http://svn.sourceforge.net/ohla/?rev=116&view=rev Author: mnewcomb Date: 2007-02-12 19:23:38 -0800 (Mon, 12 Feb 2007) Log Message: ----------- - refactoring Modified Paths: -------------- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederateIoFilter.java trunk/rti/src/java/net/sf/ohla/rti1516/local/LocalFederate.java trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/AttributeInstance.java trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectInstance.java trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectManager.java Added Paths: ----------- trunk/rti/src/java/net/sf/ohla/rti1516/SubscriptionManager.java Removed Paths: ------------- trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateRestoreState.java trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateSaveState.java trunk/rti/src/java/net/sf/ohla/rti1516/local/SubscriptionManager.java Copied: trunk/rti/src/java/net/sf/ohla/rti1516/SubscriptionManager.java (from rev 115, trunk/rti/src/java/net/sf/ohla/rti1516/local/SubscriptionManager.java) =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/SubscriptionManager.java (rev 0) +++ trunk/rti/src/java/net/sf/ohla/rti1516/SubscriptionManager.java 2007-02-13 03:23:38 UTC (rev 116) @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2006, Michael Newcomb + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.sf.ohla.rti1516; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import net.sf.ohla.rti1516.fdd.InteractionClass; +import net.sf.ohla.rti1516.fdd.ObjectClass; + +import hla.rti1516.AttributeHandle; +import hla.rti1516.AttributeHandleSet; +import hla.rti1516.AttributeRegionAssociation; +import hla.rti1516.AttributeSetRegionSetPairList; +import hla.rti1516.InteractionClassHandle; +import hla.rti1516.ObjectClassHandle; +import hla.rti1516.RegionHandle; +import hla.rti1516.RegionHandleSet; +import hla.rti1516.AttributeHandleValueMap; + +public class SubscriptionManager +{ + protected Map<ObjectClassHandle, Map<AttributeHandle, AttributeSubscription>> + subscribedObjectClasses = + new HashMap<ObjectClassHandle, Map<AttributeHandle, AttributeSubscription>>(); + + protected Map<InteractionClassHandle, InteractionClassSubscription> + subscribedInteractionClasses = + new HashMap<InteractionClassHandle, InteractionClassSubscription>(); + + public boolean isObjectClassSubscribed(ObjectClassHandle objectClassHandle) + { + return subscribedObjectClasses.containsKey(objectClassHandle); + } + + public void subscribeObjectClassAttributes( + ObjectClassHandle objectClassHandle, AttributeHandleSet attributeHandles, + boolean passive) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + getAttributeSubscriptions(objectClassHandle, true); + + for (AttributeHandle attributeHandle : attributeHandles) + { + AttributeSubscription attributeSubscription = + attributeSubscriptions.get(attributeHandle); + if (attributeSubscription == null) + { + attributeSubscriptions.put( + attributeHandle, new AttributeSubscription(attributeHandle, passive)); + } + else + { + attributeSubscription.subscribe(passive); + } + } + } + + public void subscribeObjectClassAttributes( + ObjectClassHandle objectClassHandle, + AttributeSetRegionSetPairList attributesAndRegions, boolean passive) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + getAttributeSubscriptions(objectClassHandle, true); + + for (AttributeRegionAssociation attributeRegionAssociation : attributesAndRegions) + { + for (AttributeHandle attributeHandle : attributeRegionAssociation.attributes) + { + AttributeSubscription attributeSubscription = + attributeSubscriptions.get(attributeHandle); + if (attributeSubscription == null) + { + attributeSubscriptions.put( + attributeHandle, new AttributeSubscription( + attributeHandle, attributeRegionAssociation.regions, passive)); + } + else + { + attributeSubscription.subscribe( + attributeRegionAssociation.regions, passive); + } + } + } + } + + public void unsubscribeObjectClass(ObjectClassHandle objectClassHandle) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + getAttributeSubscriptions(objectClassHandle, false); + + if (attributeSubscriptions != null) + { + for (AttributeSubscription attributeSubscription : attributeSubscriptions.values()) + { + // unsubscribe from the default region + // + attributeSubscription.unsubscribe(); + } + } + } + + public void unsubscribeObjectClassAttributes( + ObjectClassHandle objectClassHandle, AttributeHandleSet attributeHandles) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + getAttributeSubscriptions(objectClassHandle, false); + + if (attributeSubscriptions != null) + { + for (AttributeHandle attributeHandle : attributeHandles) + { + AttributeSubscription attributeSubscription = + attributeSubscriptions.get(attributeHandle); + if (attributeSubscription != null) + { + // unsubscribe from the default region + // + attributeSubscription.unsubscribe(); + } + } + } + } + + public void unsubscribeObjectClassAttributes( + ObjectClassHandle objectClassHandle, + AttributeSetRegionSetPairList attributesAndRegions) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + getAttributeSubscriptions(objectClassHandle, false); + + if (attributeSubscriptions != null) + { + for (AttributeRegionAssociation attributeRegionAssociation : attributesAndRegions) + { + for (AttributeHandle attributeHandle : attributeRegionAssociation.attributes) + { + AttributeSubscription attributeSubscription = + attributeSubscriptions.get(attributeHandle); + if (attributeSubscription != null) + { + // unsubscribe from the specified regions + // + attributeSubscription.unsubscribe( + attributeRegionAssociation.regions); + } + } + } + } + } + + public boolean isInteractionClassSubscribed( + InteractionClassHandle interactionClassHandle) + { + return subscribedInteractionClasses.containsKey(interactionClassHandle); + } + + public void subscribeInteractionClass( + InteractionClassHandle interactionClassHandle, boolean passive) + { + InteractionClassSubscription interactionClassSubscription = + subscribedInteractionClasses.get(interactionClassHandle); + if (interactionClassSubscription == null) + { + subscribedInteractionClasses.put( + interactionClassHandle, + new InteractionClassSubscription(interactionClassHandle, passive)); + } + else + { + interactionClassSubscription.subscribe(passive); + } + } + + public void subscribeInteractionClass( + InteractionClassHandle interactionClassHandle, + RegionHandleSet regionHandles, boolean passive) + { + InteractionClassSubscription interactionClassSubscription = + subscribedInteractionClasses.get(interactionClassHandle); + if (interactionClassSubscription == null) + { + subscribedInteractionClasses.put( + interactionClassHandle, + new InteractionClassSubscription(interactionClassHandle, passive)); + } + else + { + interactionClassSubscription.subscribe(passive); + } + } + + public void unsubscribeInteractionClass( + InteractionClassHandle interactionClassHandle) + { + InteractionClassSubscription interactionClassSubscription = + subscribedInteractionClasses.get(interactionClassHandle); + if (interactionClassSubscription != null) + { + interactionClassSubscription.unsubscribe(); + } + } + + public void unsubscribeInteractionClass( + InteractionClassHandle interactionClassHandle, + RegionHandleSet regionHandles) + { + InteractionClassSubscription interactionClassSubscription = + subscribedInteractionClasses.get(interactionClassHandle); + if (interactionClassSubscription != null) + { + interactionClassSubscription.unsubscribe(regionHandles); + } + } + + public ObjectClass getSubscribedObjectClass(ObjectClass objectClass) + { + boolean subscribed = isObjectClassSubscribed( + objectClass.getObjectClassHandle()); + + if (!subscribed && objectClass.hasSuperObjectClass()) + { + // see if an anscestor of the object class is subscribed + + do + { + objectClass = objectClass.getSuperObjectClass(); + + subscribed = isObjectClassSubscribed( + objectClass.getObjectClassHandle()); + } while (!subscribed && objectClass.hasSuperObjectClass()); + } + + return subscribed ? objectClass : null; + } + + public InteractionClass getSubscribedInteractionClass( + InteractionClass interactionClass) + { + boolean subscribed = isInteractionClassSubscribed( + interactionClass.getInteractionClassHandle()); + + if (!subscribed && interactionClass.hasSuperInteractionClass()) + { + // see if an anscestor of the interaction class is subscribed + + do + { + interactionClass = interactionClass.getSuperInteractionClass(); + + subscribed = isInteractionClassSubscribed( + interactionClass.getInteractionClassHandle()); + } while (!subscribed && interactionClass.hasSuperInteractionClass()); + } + + return subscribed ? interactionClass : null; + } + + public void trim(AttributeHandleValueMap attributeValues, + ObjectClassHandle objectClassHandle) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + subscribedObjectClasses.get(objectClassHandle); + assert attributeSubscriptions != null; + + attributeValues.keySet().retainAll(attributeSubscriptions.keySet()); + } + + protected Map<AttributeHandle, AttributeSubscription> getSubscribedAttributeSubscriptions( + ObjectClass objectClass) + { + Map<AttributeHandle, AttributeSubscription> subscriptions = + subscribedObjectClasses.get(objectClass.getObjectClassHandle()); + if (subscriptions == null && objectClass.hasSuperObjectClass()) + { + // see if an anscestor of the object class is subscribed + + do + { + objectClass = objectClass.getSuperObjectClass(); + + subscriptions = subscribedObjectClasses.get( + objectClass.getObjectClassHandle()); + + } while (subscriptions == null && objectClass.hasSuperObjectClass()); + } + return subscriptions; + } + + protected Map<AttributeHandle, AttributeSubscription> getAttributeSubscriptions( + ObjectClassHandle objectClassHandle, boolean addIfMissing) + { + Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = + subscribedObjectClasses.get(objectClassHandle); + if (attributeSubscriptions == null && addIfMissing) + { + attributeSubscriptions = + new HashMap<AttributeHandle, AttributeSubscription>(); + subscribedObjectClasses.put(objectClassHandle, + attributeSubscriptions); + } + return attributeSubscriptions; + } + + protected abstract class AbstractSubscription + { + protected boolean defaultRegionSubscribed; + protected boolean defaultRegionPassive; + + protected Map<RegionHandle, Boolean> subscribedRegionHandles = + new HashMap<RegionHandle, Boolean>(); + + public AbstractSubscription(boolean passive) + { + subscribe(passive); + } + + public AbstractSubscription(RegionHandleSet regionHandles, boolean passive) + { + subscribe(regionHandles, passive); + } + + public boolean isDefaultRegionSubscribed() + { + return defaultRegionSubscribed; + } + + public boolean isDefaultRegionPassive() + { + return defaultRegionPassive; + } + + public Set<RegionHandle> getSubscribedRegionHandles() + { + return subscribedRegionHandles.keySet(); + } + + public void subscribe(boolean passive) + { + defaultRegionSubscribed = true; + defaultRegionPassive = passive; + } + + public void unsubscribe() + { + defaultRegionSubscribed = false; + } + + public void subscribe(RegionHandleSet regionHandles, boolean passive) + { + for (RegionHandle regionHandle : regionHandles) + { + subscribedRegionHandles.put(regionHandle, passive); + } + } + + public void unsubscribe(RegionHandleSet regionHandles) + { + for (RegionHandle regionHandle : regionHandles) + { + subscribedRegionHandles.remove(regionHandle); + } + } + } + + protected class AttributeSubscription + extends AbstractSubscription + { + protected final AttributeHandle attributeHandle; + + public AttributeSubscription(AttributeHandle attributeHandle, + boolean passive) + { + super(passive); + + this.attributeHandle = attributeHandle; + } + + public AttributeSubscription(AttributeHandle attributeHandle, + RegionHandleSet regionHandles, boolean passive) + { + super(regionHandles, passive); + + this.attributeHandle = attributeHandle; + } + } + + protected class InteractionClassSubscription + extends AbstractSubscription + { + protected final InteractionClassHandle interactionClassHandle; + + public InteractionClassSubscription( + InteractionClassHandle interactionClassHandle, boolean passive) + { + super(passive); + + this.interactionClassHandle = interactionClassHandle; + } + + public InteractionClassSubscription( + InteractionClassHandle interactionClassHandle, + RegionHandleSet regionHandles, boolean passive) + { + super(regionHandles, passive); + + this.interactionClassHandle = interactionClassHandle; + } + } +} Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederateIoFilter.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederateIoFilter.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederateIoFilter.java 2007-02-13 03:23:38 UTC (rev 116) @@ -20,8 +20,8 @@ import net.sf.ohla.rti1516.OHLAAttributeHandleValueMap; import net.sf.ohla.rti1516.OHLAParameterHandleValueMap; +import net.sf.ohla.rti1516.SubscriptionManager; import net.sf.ohla.rti1516.fdd.InteractionClass; -import net.sf.ohla.rti1516.local.SubscriptionManager; import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisition; import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisitionIfAvailable; import net.sf.ohla.rti1516.messages.AttributeOwnershipDivestitureIfWanted; Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateRestoreState.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateRestoreState.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateRestoreState.java 2007-02-13 03:23:38 UTC (rev 116) @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2006, Michael Newcomb - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.ohla.rti1516.local; - -public enum FederateRestoreState -{ - RESTORE_REQUEST_PENDING, WAITING_FOR_RESTORE_TO_BEGIN, PREPARED_TO_RESTORE, - RESTORING, WAITING_FOR_FEDERATION_TO_RESTORE -} Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateSaveState.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateSaveState.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/FederateSaveState.java 2007-02-13 03:23:38 UTC (rev 116) @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2006, Michael Newcomb - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.ohla.rti1516.local; - -public enum FederateSaveState -{ - INSTRUCTED_TO_SAVE, SAVING, WAITING_FOR_FEDERATION_TO_SAVE -} Modified: trunk/rti/src/java/net/sf/ohla/rti1516/local/LocalFederate.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/LocalFederate.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/LocalFederate.java 2007-02-13 03:23:38 UTC (rev 116) @@ -45,7 +45,6 @@ import net.sf.ohla.rti1516.OHLARegionHandleSetFactory; import net.sf.ohla.rti1516.fdd.FDD; import net.sf.ohla.rti1516.local.objects.ObjectManager; -import net.sf.ohla.rti1516.local.LocalTimeManager; import net.sf.ohla.rti1516.messages.FederateRestoreComplete; import net.sf.ohla.rti1516.messages.FederateRestoreNotComplete; import net.sf.ohla.rti1516.messages.FederateSaveBegun; @@ -198,9 +197,11 @@ import hla.rti1516.RestoreFailureReason; import hla.rti1516.RestoreInProgress; import hla.rti1516.RestoreNotRequested; +import hla.rti1516.RestoreStatus; import hla.rti1516.SaveFailureReason; import hla.rti1516.SaveInProgress; import hla.rti1516.SaveNotInitiated; +import hla.rti1516.SaveStatus; import hla.rti1516.ServiceGroup; import hla.rti1516.SpecifiedSaveLabelDoesNotExist; import hla.rti1516.SynchronizationPointFailureReason; @@ -245,10 +246,10 @@ protected ReadWriteLock federateStateLock = new ReentrantReadWriteLock(true); - protected FederateSaveState federateSaveState; + protected SaveStatus saveStatus; protected FederateSave federateSave; - protected FederateRestoreState federateRestoreState; + protected RestoreStatus restoreStatus; protected FederateRestore federateRestore; protected Lock synchronizationPointLock = new ReentrantLock(true); @@ -857,14 +858,14 @@ federateStateLock.readLock().lock(); try { - if (federateSaveState != FederateSaveState.INSTRUCTED_TO_SAVE) + if (saveStatus != SaveStatus.FEDERATE_INSTRUCTED_TO_SAVE) { throw new SaveNotInitiated(); } writeFuture = rtiSession.write(new FederateSaveBegun()); - federateSaveState = FederateSaveState.SAVING; + saveStatus = SaveStatus.FEDERATE_SAVING; } finally { @@ -891,14 +892,14 @@ { checkIfRestoreInProgress(); - if (federateSaveState != FederateSaveState.SAVING) + if (saveStatus != SaveStatus.FEDERATE_SAVING) { throw new FederateHasNotBegunSave(); } writeFuture = rtiSession.write(new FederateSaveComplete(null)); - federateSaveState = FederateSaveState.WAITING_FOR_FEDERATION_TO_SAVE; + saveStatus = SaveStatus.FEDERATE_WAITING_FOR_FEDERATION_TO_SAVE; } finally { @@ -925,14 +926,14 @@ { checkIfRestoreInProgress(); - if (federateSaveState != FederateSaveState.SAVING) + if (saveStatus != SaveStatus.FEDERATE_SAVING) { throw new FederateHasNotBegunSave(); } writeFuture = rtiSession.write(new FederateSaveNotComplete()); - federateSaveState = FederateSaveState.WAITING_FOR_FEDERATION_TO_SAVE; + saveStatus = SaveStatus.FEDERATE_WAITING_FOR_FEDERATION_TO_SAVE; } finally { @@ -1037,15 +1038,14 @@ { checkIfSaveInProgress(); - if (federateRestoreState != FederateRestoreState.RESTORING) + if (restoreStatus != RestoreStatus.FEDERATE_RESTORING) { throw new RestoreNotRequested(); } writeFuture = rtiSession.write(new FederateRestoreComplete()); - federateRestoreState = - FederateRestoreState.WAITING_FOR_FEDERATION_TO_RESTORE; + restoreStatus = RestoreStatus.FEDERATE_WAITING_FOR_FEDERATION_TO_RESTORE; } finally { @@ -1072,15 +1072,14 @@ { checkIfSaveInProgress(); - if (federateRestoreState != FederateRestoreState.RESTORING) + if (restoreStatus != RestoreStatus.FEDERATE_RESTORING) { throw new RestoreNotRequested(); } writeFuture = rtiSession.write(new FederateRestoreNotComplete()); - federateRestoreState = - FederateRestoreState.WAITING_FOR_FEDERATION_TO_RESTORE; + restoreStatus = RestoreStatus.FEDERATE_WAITING_FOR_FEDERATION_TO_RESTORE; } finally { Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/local/SubscriptionManager.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/SubscriptionManager.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/SubscriptionManager.java 2007-02-13 03:23:38 UTC (rev 116) @@ -1,425 +0,0 @@ -/* - * Copyright (c) 2006, Michael Newcomb - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.ohla.rti1516.local; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import net.sf.ohla.rti1516.fdd.InteractionClass; -import net.sf.ohla.rti1516.fdd.ObjectClass; - -import hla.rti1516.AttributeHandle; -import hla.rti1516.AttributeHandleSet; -import hla.rti1516.AttributeRegionAssociation; -import hla.rti1516.AttributeSetRegionSetPairList; -import hla.rti1516.InteractionClassHandle; -import hla.rti1516.ObjectClassHandle; -import hla.rti1516.RegionHandle; -import hla.rti1516.RegionHandleSet; -import hla.rti1516.AttributeHandleValueMap; - -public class SubscriptionManager -{ - protected Map<ObjectClassHandle, Map<AttributeHandle, AttributeSubscription>> - subscribedObjectClasses = - new HashMap<ObjectClassHandle, Map<AttributeHandle, AttributeSubscription>>(); - - protected Map<InteractionClassHandle, InteractionClassSubscription> - subscribedInteractionClasses = - new HashMap<InteractionClassHandle, InteractionClassSubscription>(); - - public boolean isObjectClassSubscribed(ObjectClassHandle objectClassHandle) - { - return subscribedObjectClasses.containsKey(objectClassHandle); - } - - public void subscribeObjectClassAttributes( - ObjectClassHandle objectClassHandle, AttributeHandleSet attributeHandles, - boolean passive) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - getAttributeSubscriptions(objectClassHandle, true); - - for (AttributeHandle attributeHandle : attributeHandles) - { - AttributeSubscription attributeSubscription = - attributeSubscriptions.get(attributeHandle); - if (attributeSubscription == null) - { - attributeSubscriptions.put( - attributeHandle, new AttributeSubscription(attributeHandle, passive)); - } - else - { - attributeSubscription.subscribe(passive); - } - } - } - - public void subscribeObjectClassAttributes( - ObjectClassHandle objectClassHandle, - AttributeSetRegionSetPairList attributesAndRegions, boolean passive) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - getAttributeSubscriptions(objectClassHandle, true); - - for (AttributeRegionAssociation attributeRegionAssociation : attributesAndRegions) - { - for (AttributeHandle attributeHandle : attributeRegionAssociation.attributes) - { - AttributeSubscription attributeSubscription = - attributeSubscriptions.get(attributeHandle); - if (attributeSubscription == null) - { - attributeSubscriptions.put( - attributeHandle, new AttributeSubscription( - attributeHandle, attributeRegionAssociation.regions, passive)); - } - else - { - attributeSubscription.subscribe( - attributeRegionAssociation.regions, passive); - } - } - } - } - - public void unsubscribeObjectClass(ObjectClassHandle objectClassHandle) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - getAttributeSubscriptions(objectClassHandle, false); - - if (attributeSubscriptions != null) - { - for (AttributeSubscription attributeSubscription : attributeSubscriptions.values()) - { - // unsubscribe from the default region - // - attributeSubscription.unsubscribe(); - } - } - } - - public void unsubscribeObjectClassAttributes( - ObjectClassHandle objectClassHandle, AttributeHandleSet attributeHandles) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - getAttributeSubscriptions(objectClassHandle, false); - - if (attributeSubscriptions != null) - { - for (AttributeHandle attributeHandle : attributeHandles) - { - AttributeSubscription attributeSubscription = - attributeSubscriptions.get(attributeHandle); - if (attributeSubscription != null) - { - // unsubscribe from the default region - // - attributeSubscription.unsubscribe(); - } - } - } - } - - public void unsubscribeObjectClassAttributes( - ObjectClassHandle objectClassHandle, - AttributeSetRegionSetPairList attributesAndRegions) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - getAttributeSubscriptions(objectClassHandle, false); - - if (attributeSubscriptions != null) - { - for (AttributeRegionAssociation attributeRegionAssociation : attributesAndRegions) - { - for (AttributeHandle attributeHandle : attributeRegionAssociation.attributes) - { - AttributeSubscription attributeSubscription = - attributeSubscriptions.get(attributeHandle); - if (attributeSubscription != null) - { - // unsubscribe from the specified regions - // - attributeSubscription.unsubscribe( - attributeRegionAssociation.regions); - } - } - } - } - } - - public boolean isInteractionClassSubscribed( - InteractionClassHandle interactionClassHandle) - { - return subscribedInteractionClasses.containsKey(interactionClassHandle); - } - - public void subscribeInteractionClass( - InteractionClassHandle interactionClassHandle, boolean passive) - { - InteractionClassSubscription interactionClassSubscription = - subscribedInteractionClasses.get(interactionClassHandle); - if (interactionClassSubscription == null) - { - subscribedInteractionClasses.put( - interactionClassHandle, - new InteractionClassSubscription(interactionClassHandle, passive)); - } - else - { - interactionClassSubscription.subscribe(passive); - } - } - - public void subscribeInteractionClass( - InteractionClassHandle interactionClassHandle, - RegionHandleSet regionHandles, boolean passive) - { - InteractionClassSubscription interactionClassSubscription = - subscribedInteractionClasses.get(interactionClassHandle); - if (interactionClassSubscription == null) - { - subscribedInteractionClasses.put( - interactionClassHandle, - new InteractionClassSubscription(interactionClassHandle, passive)); - } - else - { - interactionClassSubscription.subscribe(passive); - } - } - - public void unsubscribeInteractionClass( - InteractionClassHandle interactionClassHandle) - { - InteractionClassSubscription interactionClassSubscription = - subscribedInteractionClasses.get(interactionClassHandle); - if (interactionClassSubscription != null) - { - interactionClassSubscription.unsubscribe(); - } - } - - public void unsubscribeInteractionClass( - InteractionClassHandle interactionClassHandle, - RegionHandleSet regionHandles) - { - InteractionClassSubscription interactionClassSubscription = - subscribedInteractionClasses.get(interactionClassHandle); - if (interactionClassSubscription != null) - { - interactionClassSubscription.unsubscribe(regionHandles); - } - } - - public ObjectClass getSubscribedObjectClass(ObjectClass objectClass) - { - boolean subscribed = isObjectClassSubscribed( - objectClass.getObjectClassHandle()); - - if (!subscribed && objectClass.hasSuperObjectClass()) - { - // see if an anscestor of the object class is subscribed - - do - { - objectClass = objectClass.getSuperObjectClass(); - - subscribed = isObjectClassSubscribed( - objectClass.getObjectClassHandle()); - } while (!subscribed && objectClass.hasSuperObjectClass()); - } - - return subscribed ? objectClass : null; - } - - public InteractionClass getSubscribedInteractionClass( - InteractionClass interactionClass) - { - boolean subscribed = isInteractionClassSubscribed( - interactionClass.getInteractionClassHandle()); - - if (!subscribed && interactionClass.hasSuperInteractionClass()) - { - // see if an anscestor of the interaction class is subscribed - - do - { - interactionClass = interactionClass.getSuperInteractionClass(); - - subscribed = isInteractionClassSubscribed( - interactionClass.getInteractionClassHandle()); - } while (!subscribed && interactionClass.hasSuperInteractionClass()); - } - - return subscribed ? interactionClass : null; - } - - public void trim(AttributeHandleValueMap attributeValues, - ObjectClassHandle objectClassHandle) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - subscribedObjectClasses.get(objectClassHandle); - assert attributeSubscriptions != null; - - attributeValues.keySet().retainAll(attributeSubscriptions.keySet()); - } - - protected Map<AttributeHandle, AttributeSubscription> getSubscribedAttributeSubscriptions( - ObjectClass objectClass) - { - Map<AttributeHandle, AttributeSubscription> subscriptions = - subscribedObjectClasses.get(objectClass.getObjectClassHandle()); - if (subscriptions == null && objectClass.hasSuperObjectClass()) - { - // see if an anscestor of the object class is subscribed - - do - { - objectClass = objectClass.getSuperObjectClass(); - - subscriptions = subscribedObjectClasses.get( - objectClass.getObjectClassHandle()); - - } while (subscriptions == null && objectClass.hasSuperObjectClass()); - } - return subscriptions; - } - - protected Map<AttributeHandle, AttributeSubscription> getAttributeSubscriptions( - ObjectClassHandle objectClassHandle, boolean addIfMissing) - { - Map<AttributeHandle, AttributeSubscription> attributeSubscriptions = - subscribedObjectClasses.get(objectClassHandle); - if (attributeSubscriptions == null && addIfMissing) - { - attributeSubscriptions = - new HashMap<AttributeHandle, AttributeSubscription>(); - subscribedObjectClasses.put(objectClassHandle, - attributeSubscriptions); - } - return attributeSubscriptions; - } - - protected abstract class AbstractSubscription - { - protected boolean defaultRegionSubscribed; - protected boolean defaultRegionPassive; - - protected Map<RegionHandle, Boolean> subscribedRegionHandles = - new HashMap<RegionHandle, Boolean>(); - - public AbstractSubscription(boolean passive) - { - subscribe(passive); - } - - public AbstractSubscription(RegionHandleSet regionHandles, boolean passive) - { - subscribe(regionHandles, passive); - } - - public boolean isDefaultRegionSubscribed() - { - return defaultRegionSubscribed; - } - - public boolean isDefaultRegionPassive() - { - return defaultRegionPassive; - } - - public Set<RegionHandle> getSubscribedRegionHandles() - { - return subscribedRegionHandles.keySet(); - } - - public void subscribe(boolean passive) - { - defaultRegionSubscribed = true; - defaultRegionPassive = passive; - } - - public void unsubscribe() - { - defaultRegionSubscribed = false; - } - - public void subscribe(RegionHandleSet regionHandles, boolean passive) - { - for (RegionHandle regionHandle : regionHandles) - { - subscribedRegionHandles.put(regionHandle, passive); - } - } - - public void unsubscribe(RegionHandleSet regionHandles) - { - for (RegionHandle regionHandle : regionHandles) - { - subscribedRegionHandles.remove(regionHandle); - } - } - } - - protected class AttributeSubscription - extends AbstractSubscription - { - protected final AttributeHandle attributeHandle; - - public AttributeSubscription(AttributeHandle attributeHandle, - boolean passive) - { - super(passive); - - this.attributeHandle = attributeHandle; - } - - public AttributeSubscription(AttributeHandle attributeHandle, - RegionHandleSet regionHandles, boolean passive) - { - super(regionHandles, passive); - - this.attributeHandle = attributeHandle; - } - } - - protected class InteractionClassSubscription - extends AbstractSubscription - { - protected final InteractionClassHandle interactionClassHandle; - - public InteractionClassSubscription( - InteractionClassHandle interactionClassHandle, boolean passive) - { - super(passive); - - this.interactionClassHandle = interactionClassHandle; - } - - public InteractionClassSubscription( - InteractionClassHandle interactionClassHandle, - RegionHandleSet regionHandles, boolean passive) - { - super(regionHandles, passive); - - this.interactionClassHandle = interactionClassHandle; - } - } -} Modified: trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/AttributeInstance.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/AttributeInstance.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/AttributeInstance.java 2007-02-13 03:23:38 UTC (rev 116) @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.sf.ohla.rti1516.federate.objects; +package net.sf.ohla.rti1516.local.objects; import java.io.Serializable; Modified: trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectInstance.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectInstance.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectInstance.java 2007-02-13 03:23:38 UTC (rev 116) @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.sf.ohla.rti1516.federate.objects; +package net.sf.ohla.rti1516.local.objects; import java.io.Serializable; Modified: trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectManager.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectManager.java 2007-02-13 03:16:02 UTC (rev 115) +++ trunk/rti/src/java/net/sf/ohla/rti1516/local/objects/ObjectManager.java 2007-02-13 03:23:38 UTC (rev 116) @@ -1,4 +1,4 @@ -package net.sf.ohla.rti1516.federate.objects; +package net.sf.ohla.rti1516.local.objects; import java.util.ArrayList; import java.util.Collection; @@ -15,10 +15,10 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import net.sf.ohla.rti1516.OHLAAttributeHandleSet; +import net.sf.ohla.rti1516.SubscriptionManager; import net.sf.ohla.rti1516.fdd.InteractionClass; import net.sf.ohla.rti1516.fdd.ObjectClass; -import net.sf.ohla.rti1516.federate.LocalFederate; -import net.sf.ohla.rti1516.federate.SubscriptionManager; +import net.sf.ohla.rti1516.local.LocalFederate; import net.sf.ohla.rti1516.messages.DeleteObjectInstance; import net.sf.ohla.rti1516.messages.RegisterObjectInstance; import net.sf.ohla.rti1516.messages.ReserveObjectInstanceName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |