PDA

View Full Version : Single instance remote object pool


oz_ko
10-31-2006, 04:14 AM
Hi all,

I have a somewhat odd requirement: I have to create a single remote object that can only be accessed by one client at a time. The remote object needs to use the serial port so it can't be reused by a second client until it is released by the first client.

I've tried creating an object pool of with a maxSize of 1 but it has no effect. i.e. multiple clients can still access the object.


<object id="serialAgentTarget" type="SerialService.SerialAgent, SerialService" singleton="false" >
<property name="CommControl" ref="commControl"/>
</object>
<!-- There can be only one! -->
<object id="poolTargetSource" type="Spring.Aop.Target.SimplePoolTargetSource, Spring.Aop">
<property name="targetObjectName" value="serialAgentTarget"/>
<property name="maxSize" value="1"/>
</object>
<object id="serialAgent" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="targetSource">
<ref local="poolTargetSource"/>
</property>
</object>


sao.xml

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:r="http://www.springframework.net/remoting">
<r:saoExporter targetName="serialAgent" serviceName="RemotedSaoSerialAgent" infinite="true"/>
</objects>


Can multiple clients still access the remote object because of the remoting proxy, or is there some other reason?

Is there a better way to do this?

Thanks
Oz

Bruno Baia
11-05-2006, 11:42 PM
Hi,

in your example, method calls of your remoted object are pooled, not the remoted object itself.

- Bruno

oz_ko
11-06-2006, 03:42 AM
Thanks Bruno,


in your example, method calls of your remoted object are pooled, not the remoted object itself.

I'm not really clear on how the proxy factory object works with remoted objects. Does this mean would just need to add:

<property name="ProxyTargetType" value="true" />


ie:

<object id="serialAgent" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="targetSource">
<ref local="poolTargetSource"/>
</property>
<property name="ProxyTargetType" value="true" />
</object>


Regards,
Oz

Bruno Baia
11-07-2006, 12:07 AM
Hi,

ProxyTargetType="true" allows you to proxy a class that does not implement any interfaces. the proxy will inherit from your target type and all your virtual methods will be proxied.
12.5.4. Proxying Classes (http://www.springframework.net/doc-latest/reference/html/aop.html#d0e7217)

You should try to export the pool itself.


- Bruno