AssociationProxy<T>.getAssociation() doesn't return Association<T> ? (type parameter dropped)

1 view
Skip to first unread message

Dawid Loubser

unread,
Feb 22, 2012, 11:08:28 AM2/22/12
to Rio Users Group
Hi,

I was just wondering if there is a reason why the type parameter is
dropped on AssociationProxy<T>.getAssociation()? Would have been great
if the type parameter was passed along so that I don't need to cast
everywhere, e.g.

AssociationProxy<Foo> fooProxy = ...;
Foo foo = (Foo)fooProxy.getAssociation().getService();

Is this perhaps fixed in Rio 5.0-SNAPSHOT codebase already? Enough
reason for me to take the leap with a premature upgrade :-)

Dawid

Dennis Reedy

unread,
Feb 22, 2012, 11:48:24 AM2/22/12
to rio-...@googlegroups.com
That looks to be a bug. Although I'm not sure why you're using AssociationProxy in your code? I would suggest you use Association<Foo> directly.

Dawid Loubser

unread,
Feb 22, 2012, 11:54:13 AM2/22/12
to Rio Users Group
Oh, my bad.. it's been a long day :-S
I should not be injecting AssociationProxy<T>, but just
Association<T> (which makes perfect sense).

Up to now, we have been using plain old Java object references
internally, but in distributed systems, it perhaps makes sense to use
Association as a first-class construct in the Java code everywhere.
Once can then do very interesting things, such as wait for a certain
set of associations to be available before interacting with them,
something like:

while (!shutdown &&
waitForUsable(javaSpaceAssociation,transactionManagerAssociation))
{
// Start transaction
// Read entry from space
// Do stuff...
}

This would mean embracing Rio "internally" in our code, but there is
no way around it really if one wants reasonable behaviour (plain
references just don't cut it, and I applaud Dennis' clean Association
concept). Simple question: How do I create a default, "PENDING"
association for a given type, to logically replace the default "null"
value that an object reference would have until set? This would be the
default value, e.g.

public void MyServiceImpl implements MyService
{
private Association<JavaSpace05> spaceRef = // ??? (I want an easily-
constructed PENDING association)
}

This would allow homogenous treatment of the association, whether it's
been injected or not.

Secondly, in mock-based testing, how do I create a "DISCOVERED"
association which simply delegates to my mock object (which I will
then inject into my test subject) ?

kind regards,
Dawid
Reply all
Reply to author
Forward
0 new messages