Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Write to Clustered Partitioned space from outside of the PUs throws Except

I am looking for a way to administer my openspaces application that runs in a clustered partition. So I thought one good way would be to register a notify-container to an event and then write the event from outside an external application to the cluster. To test this theory I created a simple Event called the EchoEvent: {code} @SpaceClass public class EchoEvent { private String mMessage;

public EchoEvent()
{
}

public EchoEvent( String message )
{
    mMessage = message;
}

@SpaceId
@SpaceRouting
public String getMessage()
{
    return mMessage;
}


public boolean equals( Object o )
{
    if ( this == o ) return true;
    if ( o == null || getClass() != o.getClass() ) return false;

    EchoEvent event = ( EchoEvent ) o;

    if ( !mMessage.equals( event.mMessage ) ) return false;

    return true;
}

public int hashCode()
{
    return mMessage.hashCode();
}

} {code}

Then I created a listener class to accept the EchoEvent that will just echo whatever was passed in to the log : {code} public class EchoEventListener { private Logger mLogger = Logger.getLogger( EchoEventListener.class );

@SpaceDataEvent
public void processEchoEvent( EchoEvent event )
{
    mLogger.info( event.getMessage() );
}

} {code}

Then I wired up the event listener in my pu.xml file: {code} <bean id="echoService" class="EchoEventListener"/> <os-events:notify-container giga-space="gigaSpace" id="echoNotifyContainer"> <os-core:template> <bean class="EchoEvent"/> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="echoService"/> </os-events:annotation-adapter> </os-events:listener> </os-events:notify-container> {code} This all deployed fine and looked like it was going to work. However when I try to connect to the space from the outside I get the following Exception: {code} Exception in thread "main" org.openspaces.core.UncategorizedSpaceException: Class: com.sempra.srm.realtime.util.service.EchoEvent , operation: write , load-balancing: hash-based, Broadcast mode: BROADCAST_IF_NULL_VALUES , problem: no explicit index defined; nested exception is java.lang.RuntimeException: Class: com.sempra.srm.realtime.util.service.EchoEvent , operation: write , load-balancing: hash-based, Broadcast mode: BROADCAST_IF_NULL_VALUES , problem: no explicit index defined at org.openspaces.core.exception.DefaultExceptionTranslator.translate(DefaultExceptionTranslator.java:47) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:311) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:303) at com.sempra.srm.realtime.util.TestSpaceClearEventListener.main(TestSpaceClearEventListener.java:47) Caused by: java.lang.RuntimeException: Class: com.sempra.srm.realtime.util.service.EchoEvent , operation: write , load-balancing: hash-based, Broadcast mode: BROADCAST_IF_NULL_VALUES , problem: no explicit index defined at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.getFieldBasedHashValueAbs(SourceFile:1680) at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.selectMemberHashBased_pos(SourceFile:1371) at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.selectMemberHashBased(SourceFile:1309) at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.GetNextFromPolicy(SourceFile:999) at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.selectMemberForOperationMain(SourceFile:372) at com.gigaspaces.cluster.loadbalance.LoadBalanceImpl.selectMemberForOperation(SourceFile:229) at com.j_spaces.core.cluster.JSpaceClusteredProxy.getLBRemoteJSpace(SourceFile:1292) at com.j_spaces.core.cluster.JSpaceClusteredProxy.prepareForMethodCall(SourceFile:979) at com.j_spaces.core.cluster.action.ClusterSpaceWriteActionListener.write(SourceFile:103) at com.j_spaces.core.cluster.action.ClusterSpaceWriteActionListener.onAction(SourceFile:88) at com.j_spaces.core.cluster.action.ClusterSpaceWriteActionListener.onAction(SourceFile:39) at com.j_spaces.core.client.AbstractSpaceProxy.write(SourceFile:426) at com.j_spaces.core.client.AbstractSpaceProxy.write(SourceFile:416) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:309) {code}

Here is the code that I used to try to write to the space which throws the exception: {code} public class TestSpaceClearEventListener { public static void main( String[] args ) throws Exception { String gigaSpaceUrl = "jini://localhost/*/MyClsuster?groups=giga.hblumenf&securityManager=false";

    IJSpace space  = ( IJSpace ) SpaceFinder.find( gigaSpaceUrl );

    GigaSpaceFactoryBean gsfb = new GigaSpaceFactoryBean();
    gsfb.setSpace( space );
    gsfb.afterPropertiesSet();

    GigaSpace gigaSpace = ( GigaSpace ) gsfb.getObject();

    EchoEvent event = new EchoEvent( "Hello World" );
    gigaSpace.write(event);

} {code}

Am I doing something wrong? I am able to write other @SpaceClass pojos to the space from the outside using the same mechanism, however writing one that has an notify-container or polling-container listening to it fails in this manner. I am using Gigaspace 6.0 build 1809.

Any information would be most helpful.

Edited by: Harley Blumenfeld on Apr 2, 2008 6:03 PM

Edited by: Harley Blumenfeld on Apr 2, 2008 6:04 PM

Edited by: Harley Blumenfeld on Apr 2, 2008 6:04 PM

Edited by: Harley Blumenfeld on Apr 2, 2008 6:05 PM

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=1930]{quote}

asked 2008-04-02 17:01:32 -0500

harley gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
0

Please note it is not recommended to use a string with many chars as the Space Entry UID.
It will impact the entry footprint and the time it takes to find the entry when searching it via its UID.
Use integer field instead.
Long

answered 2008-04-06 03:39:00 -0500

shay hassidim gravatar image
edit flag offensive delete link more
0

EchoEvent needed a setter for the mMessage variable. Since that was the space Id and routing field, it was unable to be set, hence would be null and could not be routed.

I added the following and the whole thing worked like a charm. {code} public void setMessage( String message ) { mMessage = message; } {code}

Rookie mistake, granted the error message could have been better, but I should have remembered that a space class needs to follow the spec of having a setter for every member that needs to be persisted across the wire.

It would be nice if GigaSpaces verified these things during deployment for notify containers and gave either an error or warning message of some sort.

answered 2008-04-04 09:12:07 -0500

harley gravatar image
edit flag offensive delete link more

Comments

Having com.gigaspaces.pojo.level = ALL as part of the gs_logging.properties would display helpful log messages to track such mistakes. Shay

shay hassidim gravatar imageshay hassidim ( 2008-04-05 15:05:03 -0500 )edit
0

Shay, Ilya,

Thanks for replying to my post.

I implemented hashCode on the event as an experiment since I got the same exception before I had a hashCode method on the class. This case of just echoing the message is kind of contrived, but I wanted to try the simplest case just to see how I could get this working for other situations. In this case I don't care which PU takes the entity and processes it, and in that case whether we are hashing on the memory reference of the object (default hashCode implementation) or of the string contents it really doesn't matter.

I am sure that the classes are in my shared-lib and compiled.

I see a template listed in the UI for the class EchoEvent, but that is about it. How do I see the notify container in the UI?

I will try experimenting with the template clause.

I think that Illya's post might be onto something. I was assuming that my error was coming from the POJO that I was writing to the space, not the template that the notify container is listening on.

I guess my next question is this, should I be using an auto-generated space id instead of using the payload (mMessage) as the routing field?

answered 2008-04-04 08:11:37 -0500

harley gravatar image
edit flag offensive delete link more
0

I got an answer to this a few days ago...

http://www.openspaces.org/forum/threa...

answered 2008-04-03 01:10:32 -0500

isterin gravatar image
edit flag offensive delete link more

Comments

Any special reason why you implement hashCode and equals for the EchoEvent class?
The object is routed to the relevant partition using the mMessage hashcode and not the EchoEvent hashCode.

Based on the exception there is no routing field or no indexed field declared with the POJO.

Are you sure your code is properly compiled and placed as part of the shared-lib of the processing unit running the notify container?
Can you try SQL template instead of regular template (have empty where condition)?
Do you see the notify template as part of the UI?

Shay

shay hassidim gravatar imageshay hassidim ( 2008-04-03 11:21:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-04-02 17:01:32 -0500

Seen: 88 times

Last updated: Apr 06 '08