Revision: 80
http://svn.sourceforge.net/ohla/?rev=80&view=rev
Author: mnewcomb
Date: 2006-12-15 19:16:37 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
refactoring in preparation of moving to centralized RTI
Modified Paths:
--------------
trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java
Added Paths:
-----------
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstance.java
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstance.java
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectManager.java
Removed Paths:
-------------
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstanceOwnership.java
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstanceOwnership.java
trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/OwnershipManager.java
trunk/rti/src/java/net/sf/ohla/rti1516/federation/ownership/
Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2006-12-16 03:12:41 UTC (rev 79)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -35,7 +35,7 @@
import net.sf.ohla.rti1516.federate.callbacks.FederationSynchronized;
import net.sf.ohla.rti1516.federate.callbacks.InitiateFederateSave;
import net.sf.ohla.rti1516.federate.callbacks.RemoveObjectInstance;
-import net.sf.ohla.rti1516.federation.ownership.OwnershipManager;
+import net.sf.ohla.rti1516.federation.objects.ObjectManager;
import net.sf.ohla.rti1516.federation.time.TimeKeeper;
import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisition;
import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisitionIfAvailable;
@@ -140,7 +140,7 @@
protected Map<RegionHandle, Map<DimensionHandle, RangeBounds>> regions =
new HashMap<RegionHandle, Map<DimensionHandle, RangeBounds>>();
- protected OwnershipManager ownershipManager = new OwnershipManager(this);
+ protected ObjectManager objectManager = new ObjectManager(this);
protected TimeKeeper timeKeeper;
@@ -401,7 +401,7 @@
session.write(new RequestResponse(
registerObjectInstance.getId(), objectInstanceRegistered));
- ownershipManager.registerObjectInstance(
+ objectManager.registerObjectInstance(
objectInstanceHandle, objectClass,
registerObjectInstance.getPublishedAttributeHandles(),
getFederateHandle(session));
@@ -530,7 +530,7 @@
subscribeObjectClassAttributes.getObjectClassHandle());
assert objectClass != null;
- ownershipManager.subscribeObjectClassAttributes(
+ objectManager.subscribeObjectClassAttributes(
objectClass, subscribeObjectClassAttributes.getAttributeHandles(),
subscribeObjectClassAttributes.getAttributesAndRegions(), session);
}
@@ -1060,7 +1060,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.unconditionalAttributeOwnershipDivestiture(
+ objectManager.unconditionalAttributeOwnershipDivestiture(
unconditionalAttributeOwnershipDivestiture.getObjectInstanceHandle(),
unconditionalAttributeOwnershipDivestiture.getAttributeHandles());
}
@@ -1077,7 +1077,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.negotiatedAttributeOwnershipDivestiture(
+ objectManager.negotiatedAttributeOwnershipDivestiture(
negotiatedAttributeOwnershipDivestiture.getObjectInstanceHandle(),
negotiatedAttributeOwnershipDivestiture.getAttributeHandles(),
negotiatedAttributeOwnershipDivestiture.getTag(), session);
@@ -1094,7 +1094,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.confirmDivestiture(
+ objectManager.confirmDivestiture(
confirmDivestiture.getObjectInstanceHandle(),
confirmDivestiture.getAttributeHandles());
}
@@ -1111,7 +1111,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.attributeOwnershipAcquisition(
+ objectManager.attributeOwnershipAcquisition(
attributeOwnershipAcquisition.getObjectInstanceHandle(),
attributeOwnershipAcquisition.getAttributeHandles(),
attributeOwnershipAcquisition.getTag(), getFederateHandle(session),
@@ -1130,7 +1130,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.attributeOwnershipAcquisitionIfAvailable(
+ objectManager.attributeOwnershipAcquisitionIfAvailable(
attributeOwnershipAcquisitionIfAvailable.getObjectInstanceHandle(),
attributeOwnershipAcquisitionIfAvailable.getAttributeHandles(),
getFederateHandle(session), session);
@@ -1149,7 +1149,7 @@
try
{
Map<AttributeHandle, FederateHandle> newOwners =
- ownershipManager.attributeOwnershipDivestitureIfWanted(
+ objectManager.attributeOwnershipDivestitureIfWanted(
attributeOwnershipDivestitureIfWanted.getObjectInstanceHandle(),
attributeOwnershipDivestitureIfWanted.getAttributeHandles());
@@ -1235,7 +1235,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.cancelNegotiatedAttributeOwnershipDivestiture(
+ objectManager.cancelNegotiatedAttributeOwnershipDivestiture(
cancelNegotiatedAttributeOwnershipDivestiture.getObjectInstanceHandle(),
cancelNegotiatedAttributeOwnershipDivestiture.getAttributeHandles(),
getFederateHandle(session));
@@ -1253,7 +1253,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.cancelAttributeOwnershipAcquisition(
+ objectManager.cancelAttributeOwnershipAcquisition(
cancelAttributeOwnershipAcquisition.getObjectInstanceHandle(),
cancelAttributeOwnershipAcquisition.getAttributeHandles(),
getFederateHandle(session), session);
@@ -1270,7 +1270,7 @@
federationExecutionStateLock.readLock().lock();
try
{
- ownershipManager.queryAttributeOwnership(
+ objectManager.queryAttributeOwnership(
queryAttributeOwnership.getObjectInstanceHandle(),
queryAttributeOwnership.getAttributeHandle(), session);
}
Copied: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects (from rev 78, trunk/rti/src/java/net/sf/ohla/rti1516/federation/ownership)
Added: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstance.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstance.java (rev 0)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstance.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -0,0 +1,167 @@
+/*
+ * 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.federation.objects;
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+
+import net.sf.ohla.rti1516.fdd.Attribute;
+
+import hla.rti1516.FederateHandle;
+
+public class AttributeInstance
+{
+ protected final Attribute attribute;
+
+ protected FederateHandle owner;
+
+ /**
+ * Set if the owner of this attribute is willing to divest ownership.
+ */
+ protected boolean wantsToDivest;
+
+ /**
+ * The 'ownership' line. When federates request ownership of this attribute
+ * they are placed into a line and given ownership based upon when they
+ * entered the line.
+ */
+ protected LinkedHashSet<FederateHandle> requestingOwnership =
+ new LinkedHashSet<FederateHandle>();
+
+ public AttributeInstance(Attribute attribute)
+ {
+ this.attribute = attribute;
+ }
+
+ public Attribute getAttribute()
+ {
+ return attribute;
+ }
+
+ public FederateHandle getOwner()
+ {
+ return owner;
+ }
+
+ public void setOwner(FederateHandle owner)
+ {
+ this.owner = owner;
+ }
+
+ public boolean wantsToDivest()
+ {
+ return wantsToDivest;
+ }
+
+ public FederateHandle unconditionalAttributeOwnershipDivestiture()
+ {
+ owner = null;
+ wantsToDivest = false;
+
+ // give ownership to the next in line
+ //
+ if (!requestingOwnership.isEmpty())
+ {
+ Iterator<FederateHandle> i = requestingOwnership.iterator();
+ owner = i.next();
+ i.remove();
+ }
+
+ return owner;
+ }
+
+ public boolean negotiatedAttributeOwnershipDivestiture(byte[] tag)
+ {
+ wantsToDivest = true;
+
+ return !requestingOwnership.isEmpty();
+ }
+
+ public FederateHandle confirmDivestiture()
+ {
+ owner = null;
+ wantsToDivest = false;
+
+ // give ownership to the next in line
+ //
+ if (!requestingOwnership.isEmpty())
+ {
+ Iterator<FederateHandle> i = requestingOwnership.iterator();
+ owner = i.next();
+ i.remove();
+ }
+
+ return owner;
+ }
+
+ public FederateHandle attributeOwnershipAcquisition(FederateHandle acquiree)
+ {
+ if (!attributeOwnershipAcquisitionIfAvailable(acquiree))
+ {
+ // get in line
+ //
+ requestingOwnership.add(acquiree);
+ }
+
+ return owner;
+ }
+
+ public boolean attributeOwnershipAcquisitionIfAvailable(
+ FederateHandle acquiree)
+ {
+ if (owner == null)
+ {
+ // acquire this attribute if it is unowned
+ //
+ owner = acquiree;
+ wantsToDivest = false;
+ }
+ return owner == acquiree;
+ }
+
+ public FederateHandle attributeOwnershipDivestitureIfWanted()
+ {
+ boolean divested = !requestingOwnership.isEmpty();
+
+ // give ownership to the next in line
+ //
+ if (divested)
+ {
+ Iterator<FederateHandle> i = requestingOwnership.iterator();
+ owner = i.next();
+ i.remove();
+
+ wantsToDivest = false;
+ }
+
+ return divested ? owner : null;
+ }
+
+ public boolean cancelAttributeOwnershipAcquisition(FederateHandle acquiree)
+ {
+ return requestingOwnership.remove(acquiree);
+ }
+
+ public void cancelNegotiatedAttributeOwnershipDivestiture(
+ FederateHandle owner)
+ {
+ if (owner.equals(this.owner))
+ {
+ wantsToDivest = false;
+ }
+ }
+}
Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstanceOwnership.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/ownership/AttributeInstanceOwnership.java 2006-12-10 19:05:45 UTC (rev 78)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/AttributeInstanceOwnership.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -1,167 +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.federation.ownership;
-
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-
-import net.sf.ohla.rti1516.fdd.Attribute;
-
-import hla.rti1516.FederateHandle;
-
-public class AttributeInstanceOwnership
-{
- protected final Attribute attribute;
-
- protected FederateHandle owner;
-
- /**
- * Set if the owner of this attribute is willing to divest ownership.
- */
- protected boolean wantsToDivest;
-
- /**
- * The 'ownership' line. When federates request ownership of this attribute
- * they are placed into a line and given ownership based upon when they
- * entered the line.
- */
- protected LinkedHashSet<FederateHandle> requestingOwnership =
- new LinkedHashSet<FederateHandle>();
-
- public AttributeInstanceOwnership(Attribute attribute)
- {
- this.attribute = attribute;
- }
-
- public Attribute getAttribute()
- {
- return attribute;
- }
-
- public FederateHandle getOwner()
- {
- return owner;
- }
-
- public void setOwner(FederateHandle owner)
- {
- this.owner = owner;
- }
-
- public boolean wantsToDivest()
- {
- return wantsToDivest;
- }
-
- public FederateHandle unconditionalAttributeOwnershipDivestiture()
- {
- owner = null;
- wantsToDivest = false;
-
- // give ownership to the next in line
- //
- if (!requestingOwnership.isEmpty())
- {
- Iterator<FederateHandle> i = requestingOwnership.iterator();
- owner = i.next();
- i.remove();
- }
-
- return owner;
- }
-
- public boolean negotiatedAttributeOwnershipDivestiture(byte[] tag)
- {
- wantsToDivest = true;
-
- return !requestingOwnership.isEmpty();
- }
-
- public FederateHandle confirmDivestiture()
- {
- owner = null;
- wantsToDivest = false;
-
- // give ownership to the next in line
- //
- if (!requestingOwnership.isEmpty())
- {
- Iterator<FederateHandle> i = requestingOwnership.iterator();
- owner = i.next();
- i.remove();
- }
-
- return owner;
- }
-
- public FederateHandle attributeOwnershipAcquisition(FederateHandle acquiree)
- {
- if (!attributeOwnershipAcquisitionIfAvailable(acquiree))
- {
- // get in line
- //
- requestingOwnership.add(acquiree);
- }
-
- return owner;
- }
-
- public boolean attributeOwnershipAcquisitionIfAvailable(
- FederateHandle acquiree)
- {
- if (owner == null)
- {
- // acquire this attribute if it is unowned
- //
- owner = acquiree;
- wantsToDivest = false;
- }
- return owner == acquiree;
- }
-
- public FederateHandle attributeOwnershipDivestitureIfWanted()
- {
- boolean divested = !requestingOwnership.isEmpty();
-
- // give ownership to the next in line
- //
- if (divested)
- {
- Iterator<FederateHandle> i = requestingOwnership.iterator();
- owner = i.next();
- i.remove();
-
- wantsToDivest = false;
- }
-
- return divested ? owner : null;
- }
-
- public boolean cancelAttributeOwnershipAcquisition(FederateHandle acquiree)
- {
- return requestingOwnership.remove(acquiree);
- }
-
- public void cancelNegotiatedAttributeOwnershipDivestiture(
- FederateHandle owner)
- {
- if (owner.equals(this.owner))
- {
- wantsToDivest = false;
- }
- }
-}
Added: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstance.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstance.java (rev 0)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstance.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -0,0 +1,450 @@
+/*
+ * 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.federation.objects;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import net.sf.ohla.rti1516.fdd.ObjectClass;
+import net.sf.ohla.rti1516.fdd.Attribute;
+import net.sf.ohla.rti1516.federate.callbacks.AttributeOwnershipAcquisitionNotification;
+import net.sf.ohla.rti1516.federate.callbacks.AttributeOwnershipUnavailable;
+import net.sf.ohla.rti1516.federate.callbacks.ConfirmAttributeOwnershipAcquisitionCancellation;
+import net.sf.ohla.rti1516.federate.callbacks.RequestAttributeOwnershipRelease;
+import net.sf.ohla.rti1516.federate.callbacks.RequestDivestitureConfirmation;
+import net.sf.ohla.rti1516.federate.callbacks.AttributeIsNotOwned;
+import net.sf.ohla.rti1516.federate.callbacks.AttributeIsOwnedByRTI;
+import net.sf.ohla.rti1516.federate.callbacks.InformAttributeOwnership;
+import net.sf.ohla.rti1516.OHLAAttributeHandleSet;
+import net.sf.ohla.rti1516.federation.FederationExecution;
+
+import org.apache.mina.common.IoSession;
+
+import hla.rti1516.AttributeHandle;
+import hla.rti1516.AttributeHandleSet;
+import hla.rti1516.FederateHandle;
+import hla.rti1516.ObjectInstanceHandle;
+
+public class ObjectInstance
+{
+ protected ObjectInstanceHandle objectInstanceHandle;
+ protected ObjectClass objectClass;
+
+ protected Lock objectLock = new ReentrantLock(true);
+
+ protected Map<AttributeHandle, AttributeInstance> attributes =
+ new HashMap<AttributeHandle, AttributeInstance>();
+
+ public ObjectInstance(ObjectInstanceHandle objectInstanceHandle,
+ ObjectClass objectClass,
+ Set<AttributeHandle> publishedAttributeHandles,
+ FederateHandle owner)
+ {
+ this.objectInstanceHandle = objectInstanceHandle;
+ this.objectClass = objectClass;
+
+ for (Attribute attribute : objectClass.getAttributes().values())
+ {
+ AttributeInstance attributeInstance =
+ new AttributeInstance(attribute);
+ attributes.put(attribute.getAttributeHandle(),
+ attributeInstance);
+
+ if (publishedAttributeHandles.contains(attribute.getAttributeHandle()))
+ {
+ attributeInstance.setOwner(owner);
+ }
+ }
+ }
+
+ public ObjectInstanceHandle getObjectInstanceHandle()
+ {
+ return objectInstanceHandle;
+ }
+
+ public ObjectClass getObjectClass()
+ {
+ return objectClass;
+ }
+
+ public FederateHandle getOwner(AttributeHandle attributeHandle)
+ {
+ return attributes.get(attributeHandle).getOwner();
+ }
+
+ public void unconditionalAttributeOwnershipDivestiture(
+ AttributeHandleSet attributeHandles,
+ FederationExecution federationExecution)
+ {
+ objectLock.lock();
+ try
+ {
+ Map<FederateHandle, AttributeHandleSet> newOwners =
+ new HashMap<FederateHandle, AttributeHandleSet>();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ FederateHandle newOwner =
+ attributes.get(
+ attributeHandle).unconditionalAttributeOwnershipDivestiture();
+ if (newOwner != null)
+ {
+ AttributeHandleSet acquiredAttributes = newOwners.get(newOwner);
+ if (acquiredAttributes == null)
+ {
+ acquiredAttributes = new OHLAAttributeHandleSet();
+ newOwners.put(newOwner, acquiredAttributes);
+ }
+ acquiredAttributes.add(attributeHandle);
+ }
+ }
+
+ // notify the new owners
+ //
+ for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
+ newOwners.entrySet())
+ {
+ IoSession ownerSession =
+ federationExecution.getFederateSession(entry.getKey());
+ if (ownerSession != null)
+ {
+ ownerSession.write(new AttributeOwnershipAcquisitionNotification(
+ objectInstanceHandle, entry.getValue()));
+ }
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void negotiatedAttributeOwnershipDivestiture(
+ AttributeHandleSet attributeHandles, byte[] tag, IoSession session)
+ {
+ objectLock.lock();
+ try
+ {
+ AttributeHandleSet divestableAttributeHandles =
+ new OHLAAttributeHandleSet();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ if (attributes.get(
+ attributeHandle).negotiatedAttributeOwnershipDivestiture(tag))
+ {
+ divestableAttributeHandles.add(attributeHandle);
+ }
+ }
+
+ if (!divestableAttributeHandles.isEmpty())
+ {
+ session.write(new RequestDivestitureConfirmation(
+ objectInstanceHandle, divestableAttributeHandles));
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void confirmDivestiture(AttributeHandleSet attributeHandles,
+ FederationExecution federationExecution)
+ {
+ objectLock.lock();
+ try
+ {
+ Map<FederateHandle, AttributeHandleSet> newOwners =
+ new HashMap<FederateHandle, AttributeHandleSet>();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ FederateHandle newOwner =
+ attributes.get(attributeHandle).confirmDivestiture();
+ if (newOwner != null)
+ {
+ AttributeHandleSet acquiredAttributes = newOwners.get(newOwner);
+ if (acquiredAttributes == null)
+ {
+ acquiredAttributes = new OHLAAttributeHandleSet();
+ newOwners.put(newOwner, acquiredAttributes);
+ }
+ acquiredAttributes.add(attributeHandle);
+ System.out.printf("%s - %s\n", newOwner, acquiredAttributes);
+ }
+ }
+
+ // notify the new owners
+ //
+ for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
+ newOwners.entrySet())
+ {
+ IoSession ownerSession =
+ federationExecution.getFederateSession(entry.getKey());
+ if (ownerSession != null)
+ {
+ ownerSession.write(new AttributeOwnershipAcquisitionNotification(
+ objectInstanceHandle, entry.getValue()));
+ }
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void attributeOwnershipAcquisition(
+ AttributeHandleSet attributeHandles, byte[] tag, FederateHandle acquiree,
+ IoSession session, FederationExecution federationExecution)
+ {
+ objectLock.lock();
+ try
+ {
+ AttributeHandleSet acquiredAttributeHandles =
+ new OHLAAttributeHandleSet();
+ Map<FederateHandle, AttributeHandleSet> federatesThatNeedToConfirmDivestiture =
+ new HashMap<FederateHandle, AttributeHandleSet>();
+ Map<FederateHandle, AttributeHandleSet> federatesThatNeedToRelease =
+ new HashMap<FederateHandle, AttributeHandleSet>();
+
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ AttributeInstance attributeInstance =
+ attributes.get(attributeHandle);
+
+ FederateHandle owner =
+ attributeInstance.attributeOwnershipAcquisition(acquiree);
+ if (acquiree.equals(owner))
+ {
+ // the attribute was unowned and therefore immediately acquired
+ //
+ acquiredAttributeHandles.add(attributeHandle);
+ }
+ else if (attributeInstance.wantsToDivest())
+ {
+ // the attribute is owned but the owner is willing to divest
+ //
+ AttributeHandleSet divestingAttributeHandles =
+ federatesThatNeedToConfirmDivestiture.get(owner);
+ if (divestingAttributeHandles == null)
+ {
+ divestingAttributeHandles = new OHLAAttributeHandleSet();
+ federatesThatNeedToConfirmDivestiture.put(
+ owner, divestingAttributeHandles);
+ }
+ divestingAttributeHandles.add(attributeHandle);
+ }
+ else
+ {
+ // the attribute is owned but the owner is unwilling to divest
+ //
+ AttributeHandleSet releasingAttributeHandles =
+ federatesThatNeedToRelease.get(owner);
+ if (releasingAttributeHandles == null)
+ {
+ releasingAttributeHandles = new OHLAAttributeHandleSet();
+ federatesThatNeedToRelease.put(owner, releasingAttributeHandles);
+ }
+ releasingAttributeHandles.add(attributeHandle);
+ }
+ }
+
+ if (!acquiredAttributeHandles.isEmpty())
+ {
+ session.write(new AttributeOwnershipAcquisitionNotification(
+ objectInstanceHandle, acquiredAttributeHandles, tag));
+ }
+
+ for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
+ federatesThatNeedToConfirmDivestiture.entrySet())
+ {
+ IoSession federateSession =
+ federationExecution.getFederateSession(entry.getKey());
+ if (federateSession != null)
+ {
+ federateSession.write(new RequestDivestitureConfirmation(
+ objectInstanceHandle, entry.getValue()));
+ }
+ }
+
+ for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
+ federatesThatNeedToRelease.entrySet())
+ {
+ IoSession federateSession =
+ federationExecution.getFederateSession(entry.getKey());
+ if (federateSession != null)
+ {
+ federateSession.write(new RequestAttributeOwnershipRelease(
+ objectInstanceHandle, entry.getValue(), tag));
+ }
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void attributeOwnershipAcquisitionIfAvailable(
+ AttributeHandleSet attributeHandles, FederateHandle acquiree,
+ IoSession session)
+ {
+ objectLock.lock();
+ try
+ {
+ AttributeHandleSet acquiredAttributeHandles =
+ new OHLAAttributeHandleSet();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ if (attributes.get(
+ attributeHandle).attributeOwnershipAcquisitionIfAvailable(acquiree))
+ {
+ acquiredAttributeHandles.add(attributeHandle);
+ }
+ }
+
+ if (!acquiredAttributeHandles.isEmpty())
+ {
+ session.write(new AttributeOwnershipAcquisitionNotification(
+ objectInstanceHandle, acquiredAttributeHandles));
+ }
+
+ AttributeHandleSet unacquiredAttributeHandles =
+ new OHLAAttributeHandleSet(attributeHandles);
+ unacquiredAttributeHandles.removeAll(acquiredAttributeHandles);
+
+ if (!unacquiredAttributeHandles.isEmpty())
+ {
+ session.write(new AttributeOwnershipUnavailable(
+ objectInstanceHandle, unacquiredAttributeHandles));
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public Map<AttributeHandle, FederateHandle> attributeOwnershipDivestitureIfWanted(
+ AttributeHandleSet attributeHandles)
+ {
+ objectLock.lock();
+ try
+ {
+ Map<AttributeHandle, FederateHandle> newOwners =
+ new HashMap<AttributeHandle, FederateHandle>();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ FederateHandle newOwner = attributes.get(
+ attributeHandle).attributeOwnershipDivestitureIfWanted();
+ if (newOwner != null)
+ {
+ newOwners.put(attributeHandle, newOwner);
+ }
+ }
+
+ return newOwners;
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void cancelNegotiatedAttributeOwnershipDivestiture(
+ AttributeHandleSet attributeHandles, FederateHandle owner)
+ {
+ objectLock.lock();
+ try
+ {
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ attributes.get(
+ attributeHandle).cancelNegotiatedAttributeOwnershipDivestiture(owner);
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void cancelAttributeOwnershipAcquisition(
+ AttributeHandleSet attributeHandles, FederateHandle acquiree,
+ IoSession session)
+ {
+ objectLock.lock();
+ try
+ {
+ AttributeHandleSet canceledOwnershipAcquisitionAttributeHandles =
+ new OHLAAttributeHandleSet();
+ for (AttributeHandle attributeHandle : attributeHandles)
+ {
+ if (attributes.get(
+ attributeHandle).cancelAttributeOwnershipAcquisition(acquiree))
+ {
+ canceledOwnershipAcquisitionAttributeHandles.add(attributeHandle);
+ }
+ }
+
+ if (!canceledOwnershipAcquisitionAttributeHandles.isEmpty())
+ {
+ session.write(new ConfirmAttributeOwnershipAcquisitionCancellation(
+ objectInstanceHandle, canceledOwnershipAcquisitionAttributeHandles));
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+
+ public void queryAttributeOwnership(AttributeHandle attributeHandle,
+ IoSession session)
+ {
+ objectLock.lock();
+ try
+ {
+ AttributeInstance attributeInstance =
+ attributes.get(attributeHandle);
+ assert attributeInstance != null;
+
+ FederateHandle owner = attributeInstance.getOwner();
+ if (owner == null)
+ {
+ session.write(new AttributeIsNotOwned(
+ objectInstanceHandle, attributeHandle));
+ }
+ else if (attributeInstance.getAttribute().isMOM())
+ {
+ session.write(new AttributeIsOwnedByRTI(
+ objectInstanceHandle, attributeHandle));
+ }
+ else
+ {
+ session.write(new InformAttributeOwnership(
+ objectInstanceHandle, attributeHandle, owner));
+ }
+ }
+ finally
+ {
+ objectLock.unlock();
+ }
+ }
+}
Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstanceOwnership.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/ownership/ObjectInstanceOwnership.java 2006-12-10 19:05:45 UTC (rev 78)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectInstanceOwnership.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -1,450 +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.federation.ownership;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import net.sf.ohla.rti1516.fdd.ObjectClass;
-import net.sf.ohla.rti1516.fdd.Attribute;
-import net.sf.ohla.rti1516.federate.callbacks.AttributeOwnershipAcquisitionNotification;
-import net.sf.ohla.rti1516.federate.callbacks.AttributeOwnershipUnavailable;
-import net.sf.ohla.rti1516.federate.callbacks.ConfirmAttributeOwnershipAcquisitionCancellation;
-import net.sf.ohla.rti1516.federate.callbacks.RequestAttributeOwnershipRelease;
-import net.sf.ohla.rti1516.federate.callbacks.RequestDivestitureConfirmation;
-import net.sf.ohla.rti1516.federate.callbacks.AttributeIsNotOwned;
-import net.sf.ohla.rti1516.federate.callbacks.AttributeIsOwnedByRTI;
-import net.sf.ohla.rti1516.federate.callbacks.InformAttributeOwnership;
-import net.sf.ohla.rti1516.OHLAAttributeHandleSet;
-import net.sf.ohla.rti1516.federation.FederationExecution;
-
-import org.apache.mina.common.IoSession;
-
-import hla.rti1516.AttributeHandle;
-import hla.rti1516.AttributeHandleSet;
-import hla.rti1516.FederateHandle;
-import hla.rti1516.ObjectInstanceHandle;
-
-public class ObjectInstanceOwnership
-{
- protected ObjectInstanceHandle objectInstanceHandle;
- protected ObjectClass objectClass;
-
- protected Lock objectLock = new ReentrantLock(true);
-
- protected Map<AttributeHandle, AttributeInstanceOwnership> attributes =
- new HashMap<AttributeHandle, AttributeInstanceOwnership>();
-
- public ObjectInstanceOwnership(ObjectInstanceHandle objectInstanceHandle,
- ObjectClass objectClass,
- Set<AttributeHandle> publishedAttributeHandles,
- FederateHandle owner)
- {
- this.objectInstanceHandle = objectInstanceHandle;
- this.objectClass = objectClass;
-
- for (Attribute attribute : objectClass.getAttributes().values())
- {
- AttributeInstanceOwnership attributeInstanceOwnership =
- new AttributeInstanceOwnership(attribute);
- attributes.put(attribute.getAttributeHandle(),
- attributeInstanceOwnership);
-
- if (publishedAttributeHandles.contains(attribute.getAttributeHandle()))
- {
- attributeInstanceOwnership.setOwner(owner);
- }
- }
- }
-
- public ObjectInstanceHandle getObjectInstanceHandle()
- {
- return objectInstanceHandle;
- }
-
- public ObjectClass getObjectClass()
- {
- return objectClass;
- }
-
- public FederateHandle getOwner(AttributeHandle attributeHandle)
- {
- return attributes.get(attributeHandle).getOwner();
- }
-
- public void unconditionalAttributeOwnershipDivestiture(
- AttributeHandleSet attributeHandles,
- FederationExecution federationExecution)
- {
- objectLock.lock();
- try
- {
- Map<FederateHandle, AttributeHandleSet> newOwners =
- new HashMap<FederateHandle, AttributeHandleSet>();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- FederateHandle newOwner =
- attributes.get(
- attributeHandle).unconditionalAttributeOwnershipDivestiture();
- if (newOwner != null)
- {
- AttributeHandleSet acquiredAttributes = newOwners.get(newOwner);
- if (acquiredAttributes == null)
- {
- acquiredAttributes = new OHLAAttributeHandleSet();
- newOwners.put(newOwner, acquiredAttributes);
- }
- acquiredAttributes.add(attributeHandle);
- }
- }
-
- // notify the new owners
- //
- for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
- newOwners.entrySet())
- {
- IoSession ownerSession =
- federationExecution.getFederateSession(entry.getKey());
- if (ownerSession != null)
- {
- ownerSession.write(new AttributeOwnershipAcquisitionNotification(
- objectInstanceHandle, entry.getValue()));
- }
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void negotiatedAttributeOwnershipDivestiture(
- AttributeHandleSet attributeHandles, byte[] tag, IoSession session)
- {
- objectLock.lock();
- try
- {
- AttributeHandleSet divestableAttributeHandles =
- new OHLAAttributeHandleSet();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- if (attributes.get(
- attributeHandle).negotiatedAttributeOwnershipDivestiture(tag))
- {
- divestableAttributeHandles.add(attributeHandle);
- }
- }
-
- if (!divestableAttributeHandles.isEmpty())
- {
- session.write(new RequestDivestitureConfirmation(
- objectInstanceHandle, divestableAttributeHandles));
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void confirmDivestiture(AttributeHandleSet attributeHandles,
- FederationExecution federationExecution)
- {
- objectLock.lock();
- try
- {
- Map<FederateHandle, AttributeHandleSet> newOwners =
- new HashMap<FederateHandle, AttributeHandleSet>();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- FederateHandle newOwner =
- attributes.get(attributeHandle).confirmDivestiture();
- if (newOwner != null)
- {
- AttributeHandleSet acquiredAttributes = newOwners.get(newOwner);
- if (acquiredAttributes == null)
- {
- acquiredAttributes = new OHLAAttributeHandleSet();
- newOwners.put(newOwner, acquiredAttributes);
- }
- acquiredAttributes.add(attributeHandle);
- System.out.printf("%s - %s\n", newOwner, acquiredAttributes);
- }
- }
-
- // notify the new owners
- //
- for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
- newOwners.entrySet())
- {
- IoSession ownerSession =
- federationExecution.getFederateSession(entry.getKey());
- if (ownerSession != null)
- {
- ownerSession.write(new AttributeOwnershipAcquisitionNotification(
- objectInstanceHandle, entry.getValue()));
- }
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void attributeOwnershipAcquisition(
- AttributeHandleSet attributeHandles, byte[] tag, FederateHandle acquiree,
- IoSession session, FederationExecution federationExecution)
- {
- objectLock.lock();
- try
- {
- AttributeHandleSet acquiredAttributeHandles =
- new OHLAAttributeHandleSet();
- Map<FederateHandle, AttributeHandleSet> federatesThatNeedToConfirmDivestiture =
- new HashMap<FederateHandle, AttributeHandleSet>();
- Map<FederateHandle, AttributeHandleSet> federatesThatNeedToRelease =
- new HashMap<FederateHandle, AttributeHandleSet>();
-
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- AttributeInstanceOwnership attributeInstanceOwnership =
- attributes.get(attributeHandle);
-
- FederateHandle owner =
- attributeInstanceOwnership.attributeOwnershipAcquisition(acquiree);
- if (acquiree.equals(owner))
- {
- // the attribute was unowned and therefore immediately acquired
- //
- acquiredAttributeHandles.add(attributeHandle);
- }
- else if (attributeInstanceOwnership.wantsToDivest())
- {
- // the attribute is owned but the owner is willing to divest
- //
- AttributeHandleSet divestingAttributeHandles =
- federatesThatNeedToConfirmDivestiture.get(owner);
- if (divestingAttributeHandles == null)
- {
- divestingAttributeHandles = new OHLAAttributeHandleSet();
- federatesThatNeedToConfirmDivestiture.put(
- owner, divestingAttributeHandles);
- }
- divestingAttributeHandles.add(attributeHandle);
- }
- else
- {
- // the attribute is owned but the owner is unwilling to divest
- //
- AttributeHandleSet releasingAttributeHandles =
- federatesThatNeedToRelease.get(owner);
- if (releasingAttributeHandles == null)
- {
- releasingAttributeHandles = new OHLAAttributeHandleSet();
- federatesThatNeedToRelease.put(owner, releasingAttributeHandles);
- }
- releasingAttributeHandles.add(attributeHandle);
- }
- }
-
- if (!acquiredAttributeHandles.isEmpty())
- {
- session.write(new AttributeOwnershipAcquisitionNotification(
- objectInstanceHandle, acquiredAttributeHandles, tag));
- }
-
- for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
- federatesThatNeedToConfirmDivestiture.entrySet())
- {
- IoSession federateSession =
- federationExecution.getFederateSession(entry.getKey());
- if (federateSession != null)
- {
- federateSession.write(new RequestDivestitureConfirmation(
- objectInstanceHandle, entry.getValue()));
- }
- }
-
- for (Map.Entry<FederateHandle, AttributeHandleSet> entry :
- federatesThatNeedToRelease.entrySet())
- {
- IoSession federateSession =
- federationExecution.getFederateSession(entry.getKey());
- if (federateSession != null)
- {
- federateSession.write(new RequestAttributeOwnershipRelease(
- objectInstanceHandle, entry.getValue(), tag));
- }
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void attributeOwnershipAcquisitionIfAvailable(
- AttributeHandleSet attributeHandles, FederateHandle acquiree,
- IoSession session)
- {
- objectLock.lock();
- try
- {
- AttributeHandleSet acquiredAttributeHandles =
- new OHLAAttributeHandleSet();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- if (attributes.get(
- attributeHandle).attributeOwnershipAcquisitionIfAvailable(acquiree))
- {
- acquiredAttributeHandles.add(attributeHandle);
- }
- }
-
- if (!acquiredAttributeHandles.isEmpty())
- {
- session.write(new AttributeOwnershipAcquisitionNotification(
- objectInstanceHandle, acquiredAttributeHandles));
- }
-
- AttributeHandleSet unacquiredAttributeHandles =
- new OHLAAttributeHandleSet(attributeHandles);
- unacquiredAttributeHandles.removeAll(acquiredAttributeHandles);
-
- if (!unacquiredAttributeHandles.isEmpty())
- {
- session.write(new AttributeOwnershipUnavailable(
- objectInstanceHandle, unacquiredAttributeHandles));
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public Map<AttributeHandle, FederateHandle> attributeOwnershipDivestitureIfWanted(
- AttributeHandleSet attributeHandles)
- {
- objectLock.lock();
- try
- {
- Map<AttributeHandle, FederateHandle> newOwners =
- new HashMap<AttributeHandle, FederateHandle>();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- FederateHandle newOwner = attributes.get(
- attributeHandle).attributeOwnershipDivestitureIfWanted();
- if (newOwner != null)
- {
- newOwners.put(attributeHandle, newOwner);
- }
- }
-
- return newOwners;
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void cancelNegotiatedAttributeOwnershipDivestiture(
- AttributeHandleSet attributeHandles, FederateHandle owner)
- {
- objectLock.lock();
- try
- {
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- attributes.get(
- attributeHandle).cancelNegotiatedAttributeOwnershipDivestiture(owner);
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void cancelAttributeOwnershipAcquisition(
- AttributeHandleSet attributeHandles, FederateHandle acquiree,
- IoSession session)
- {
- objectLock.lock();
- try
- {
- AttributeHandleSet canceledOwnershipAcquisitionAttributeHandles =
- new OHLAAttributeHandleSet();
- for (AttributeHandle attributeHandle : attributeHandles)
- {
- if (attributes.get(
- attributeHandle).cancelAttributeOwnershipAcquisition(acquiree))
- {
- canceledOwnershipAcquisitionAttributeHandles.add(attributeHandle);
- }
- }
-
- if (!canceledOwnershipAcquisitionAttributeHandles.isEmpty())
- {
- session.write(new ConfirmAttributeOwnershipAcquisitionCancellation(
- objectInstanceHandle, canceledOwnershipAcquisitionAttributeHandles));
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-
- public void queryAttributeOwnership(AttributeHandle attributeHandle,
- IoSession session)
- {
- objectLock.lock();
- try
- {
- AttributeInstanceOwnership attributeInstanceOwnership =
- attributes.get(attributeHandle);
- assert attributeInstanceOwnership != null;
-
- FederateHandle owner = attributeInstanceOwnership.getOwner();
- if (owner == null)
- {
- session.write(new AttributeIsNotOwned(
- objectInstanceHandle, attributeHandle));
- }
- else if (attributeInstanceOwnership.getAttribute().isMOM())
- {
- session.write(new AttributeIsOwnedByRTI(
- objectInstanceHandle, attributeHandle));
- }
- else
- {
- session.write(new InformAttributeOwnership(
- objectInstanceHandle, attributeHandle, owner));
- }
- }
- finally
- {
- objectLock.unlock();
- }
- }
-}
Added: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectManager.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectManager.java (rev 0)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/ObjectManager.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -0,0 +1,295 @@
+/*
+ * 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.federation.objects;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import net.sf.ohla.rti1516.fdd.ObjectClass;
+import net.sf.ohla.rti1516.federate.callbacks.DiscoverObjectInstance;
+import net.sf.ohla.rti1516.federation.FederationExecution;
+
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+
+import hla.rti1516.AttributeHandle;
+import hla.rti1516.AttributeHandleSet;
+import hla.rti1516.AttributeSetRegionSetPairList;
+import hla.rti1516.FederateHandle;
+import hla.rti1516.ObjectInstanceHandle;
+
+public class ObjectManager
+{
+ protected FederationExecution federationExecution;
+
+ protected ReadWriteLock objectsLock = new ReentrantReadWriteLock(true);
+ protected Map<ObjectInstanceHandle, ObjectInstance> objects =
+ new HashMap<ObjectInstanceHandle, ObjectInstance>();
+
+ public ObjectManager(FederationExecution federationExecution)
+ {
+ this.federationExecution = federationExecution;
+ }
+
+ public void registerObjectInstance(
+ ObjectInstanceHandle objectInstanceHandle, ObjectClass objectClass,
+ Set<AttributeHandle> publishedAttributeHandles, FederateHandle owner)
+ {
+ objectsLock.writeLock().lock();
+ try
+ {
+ objects.put(objectInstanceHandle, new ObjectInstance(
+ objectInstanceHandle, objectClass, publishedAttributeHandles, owner));
+ }
+ finally
+ {
+ objectsLock.writeLock().unlock();
+ }
+ }
+
+ public void subscribeObjectClassAttributes(
+ ObjectClass objectClass, AttributeHandleSet attributeHandles,
+ AttributeSetRegionSetPairList attributesAndRegions, IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ WriteFuture lastWriteFuture = null;
+ for (ObjectInstance objectInstance : objects.values())
+ {
+ if (objectClass.isAssignableFrom(
+ objectInstance.getObjectClass()))
+ {
+ // TODO: DDM
+
+ lastWriteFuture = session.write(new DiscoverObjectInstance(
+ objectInstance.getObjectInstanceHandle(),
+ objectClass.getObjectClassHandle()));
+ }
+ }
+
+ if (lastWriteFuture != null)
+ {
+ // wait until the last discover has been sent
+ //
+ lastWriteFuture.join();
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void unconditionalAttributeOwnershipDivestiture(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.unconditionalAttributeOwnershipDivestiture(
+ attributeHandles, federationExecution);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void negotiatedAttributeOwnershipDivestiture(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles, byte[] tag, IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.negotiatedAttributeOwnershipDivestiture(
+ attributeHandles, tag, session);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void confirmDivestiture(ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.confirmDivestiture(
+ attributeHandles, federationExecution);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void attributeOwnershipAcquisition(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles, byte[] tag, FederateHandle acquiree,
+ IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.attributeOwnershipAcquisition(
+ attributeHandles, tag, acquiree, session, federationExecution);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void attributeOwnershipAcquisitionIfAvailable(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles, FederateHandle acquiree,
+ IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.attributeOwnershipAcquisitionIfAvailable(
+ attributeHandles, acquiree, session);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public Map<AttributeHandle, FederateHandle> attributeOwnershipDivestitureIfWanted(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ return objectInstance != null ?
+ objectInstance.attributeOwnershipDivestitureIfWanted(
+ attributeHandles) :
+ (Map<AttributeHandle, FederateHandle>) Collections.EMPTY_MAP;
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void cancelNegotiatedAttributeOwnershipDivestiture(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles, FederateHandle owner)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.cancelNegotiatedAttributeOwnershipDivestiture(
+ attributeHandles, owner);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void cancelAttributeOwnershipAcquisition(
+ ObjectInstanceHandle objectInstanceHandle,
+ AttributeHandleSet attributeHandles, FederateHandle acquiree,
+ IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance != null)
+ {
+ objectInstance.cancelAttributeOwnershipAcquisition(
+ attributeHandles, acquiree, session);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+
+ public void queryAttributeOwnership(
+ ObjectInstanceHandle objectInstanceHandle, AttributeHandle attributeHandle,
+ IoSession session)
+ {
+ objectsLock.readLock().lock();
+ try
+ {
+ ObjectInstance objectInstance =
+ objects.get(objectInstanceHandle);
+ if (objectInstance == null)
+ {
+ // the object was deleted after a query was issued...
+ }
+ else
+ {
+ objectInstance.queryAttributeOwnership(
+ attributeHandle, session);
+ }
+ }
+ finally
+ {
+ objectsLock.readLock().unlock();
+ }
+ }
+}
Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/OwnershipManager.java
===================================================================
--- trunk/rti/src/java/net/sf/ohla/rti1516/federation/ownership/OwnershipManager.java 2006-12-10 19:05:45 UTC (rev 78)
+++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/objects/OwnershipManager.java 2006-12-16 03:16:37 UTC (rev 80)
@@ -1,295 +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.federation.ownership;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import net.sf.ohla.rti1516.fdd.ObjectClass;
-import net.sf.ohla.rti1516.federate.callbacks.DiscoverObjectInstance;
-import net.sf.ohla.rti1516.federation.FederationExecution;
-
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.WriteFuture;
-
-import hla.rti1516.AttributeHandle;
-import hla.rti1516.AttributeHandleSet;
-import hla.rti1516.AttributeSetRegionSetPairList;
-import hla.rti1516.FederateHandle;
-import hla.rti1516.ObjectInstanceHandle;
-
-public class OwnershipManager
-{
- protected FederationExecution federationExecution;
-
- protected ReadWriteLock objectsLock = new ReentrantReadWriteLock(true);
- protected Map<ObjectInstanceHandle, ObjectInstanceOwnership> objects =
- new HashMap<ObjectInstanceHandle, ObjectInstanceOwnership>();
-
- public OwnershipManager(FederationExecution federationExecution)
- {
- this.federationExecution = federationExecution;
- }
-
- public void registerObjectInstance(
- ObjectInstanceHandle objectInstanceHandle, ObjectClass objectClass,
- Set<AttributeHandle> publishedAttributeHandles, FederateHandle owner)
- {
- objectsLock.writeLock().lock();
- try
- {
- objects.put(objectInstanceHandle, new ObjectInstanceOwnership(
- objectInstanceHandle, objectClass, publishedAttributeHandles, owner));
- }
- finally
- {
- objectsLock.writeLock().unlock();
- }
- }
-
- public void subscribeObjectClassAttributes(
- ObjectClass objectClass, AttributeHandleSet attributeHandles,
- AttributeSetRegionSetPairList attributesAndRegions, IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- WriteFuture lastWriteFuture = null;
- for (ObjectInstanceOwnership objectInstanceOwnership : objects.values())
- {
- if (objectClass.isAssignableFrom(
- objectInstanceOwnership.getObjectClass()))
- {
- // TODO: DDM
-
- lastWriteFuture = session.write(new DiscoverObjectInstance(
- objectInstanceOwnership.getObjectInstanceHandle(),
- objectClass.getObjectClassHandle()));
- }
- }
-
- if (lastWriteFuture != null)
- {
- // wait until the last discover has been sent
- //
- lastWriteFuture.join();
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void unconditionalAttributeOwnershipDivestiture(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.unconditionalAttributeOwnershipDivestiture(
- attributeHandles, federationExecution);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void negotiatedAttributeOwnershipDivestiture(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles, byte[] tag, IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.negotiatedAttributeOwnershipDivestiture(
- attributeHandles, tag, session);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void confirmDivestiture(ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.confirmDivestiture(
- attributeHandles, federationExecution);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void attributeOwnershipAcquisition(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles, byte[] tag, FederateHandle acquiree,
- IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.attributeOwnershipAcquisition(
- attributeHandles, tag, acquiree, session, federationExecution);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void attributeOwnershipAcquisitionIfAvailable(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles, FederateHandle acquiree,
- IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.attributeOwnershipAcquisitionIfAvailable(
- attributeHandles, acquiree, session);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public Map<AttributeHandle, FederateHandle> attributeOwnershipDivestitureIfWanted(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- return objectInstanceOwnership != null ?
- objectInstanceOwnership.attributeOwnershipDivestitureIfWanted(
- attributeHandles) :
- (Map<AttributeHandle, FederateHandle>) Collections.EMPTY_MAP;
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void cancelNegotiatedAttributeOwnershipDivestiture(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles, FederateHandle owner)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.cancelNegotiatedAttributeOwnershipDivestiture(
- attributeHandles, owner);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void cancelAttributeOwnershipAcquisition(
- ObjectInstanceHandle objectInstanceHandle,
- AttributeHandleSet attributeHandles, FederateHandle acquiree,
- IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership != null)
- {
- objectInstanceOwnership.cancelAttributeOwnershipAcquisition(
- attributeHandles, acquiree, session);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-
- public void queryAttributeOwnership(
- ObjectInstanceHandle objectInstanceHandle, AttributeHandle attributeHandle,
- IoSession session)
- {
- objectsLock.readLock().lock();
- try
- {
- ObjectInstanceOwnership objectInstanceOwnership =
- objects.get(objectInstanceHandle);
- if (objectInstanceOwnership == null)
- {
- // the object was deleted after a query was issued...
- }
- else
- {
- objectInstanceOwnership.queryAttributeOwnership(
- attributeHandle, session);
- }
- }
- finally
- {
- objectsLock.readLock().unlock();
- }
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|