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

Ask Your Question
0

ClassCastException on write (v 7.0)

I'm attempting to share data in the space between processing units. The PU configurations are quite basic. The algorithm is simple:

PU #1:

  1. Client writes a Task object into the space.
  2. Using a PollingEventContainer, the Task is sent to a TaskSplitter pojo.
  3. The TaskSplitter reads the Task object and splits it into SubTask objects, and writes them to the space.

PU #2:

  1. A PollingEventContainer detects SubTasks, and passes them to a processing pojo.2
  2. Processing pojo does some work and writes them back to the space.

The problem is that step #3 above never completes because it fails with a ClassCastException on the write. This appears to be a class loader problem, as the cast error message display identical class names. When SubTasks are created from Tasks, I use "new", which apparently won't work.

I've tried:

  1. Putting all code in various Gigaspaces lib subdirectories (including options/pu_common).
  2. Using the spring context to create the SubTask instead of "new".
  3. Using the "Task" class loader instead of the default.
  4. Putting the code in a "shared_lib" subdirectory in the PU.
  5. And many more...

The error is always the same. I'm assuming that since PU#2 references the SubTask class (for the PollingEventContainer), the class is created in the space (and I can see it there). This is apparently done by a different class loader. How can I create new SubTasks in my code and add them to the space?

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

asked 2009-10-14 10:17:51 -0500

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

- Can you post your stack trace?
- Can you place the Space classes within the PU jar under the lib folder within their own jar and test?

The shared-lib folder should not be used with XAP 7.0.

Shay

answered 2009-10-14 10:29:03 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

I've already tried putting the code in lib in the PU. Didn't work. The trace is below. Notice my "write" diagnostic just before the trace. Below the trace, I've got the current structure of the PUs.

writing subtask to space 2009-10-14 10:05:01,559 pu1 [1] SEVERE [org.openspaces.events.polling.SimplePollingEventListenerContainer] - [taskProcessorPollingEventContainer] Execution of event listener failed; Caused by: org.openspaces.events.adapter.ListenerExecutionFailedException: Listener event method [processMessage] of class [com.df.test.TaskSplitter] threw exception; nested exception is org.openspaces.core.ObjectConversionException: net.jini.core.entry.UnusableEntryException; nested exception is com.gigaspaces.internal.metadata.converter.ConversionException: net.jini.core.entry.UnusableEntryException at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:177) at org.openspaces.events.adapter.AbstractResultEventListenerAdapter.onEvent(AbstractResultEventListenerAdapter.java:79) at org.openspaces.events.AbstractEventListenerContainer.invokeListener(AbstractEventListenerContainer.java:142) at org.openspaces.events.polling.AbstractPollingEventListenerContainer.doReceiveAndExecute(AbstractPollingEventListenerContainer.java:302) at org.openspaces.events.polling.AbstractPollingEventListenerContainer.receiveAndExecute(AbstractPollingEventListenerContainer.java:258) at org.openspaces.events.polling.SimplePollingEventListenerContainer$AsyncEventListenerInvoker.invokeListener(SimplePollingEventListenerContainer.java:697) at org.openspaces.events.polling.SimplePollingEventListenerContainer$AsyncEventListenerInvoker.run(SimplePollingEventListenerContainer.java:638) at java.lang.Thread.run(Thread.java:619) Caused by: org.openspaces.core.ObjectConversionException: net.jini.core.entry.UnusableEntryException; nested exception is com.gigaspaces.internal.metadata.converter.ConversionException: net.jini.core.entry.UnusableEntryException at org.openspaces.core.exception.DefaultExceptionTranslator.internalTranslate(DefaultExceptionTranslator.java:113) at org.openspaces.core.exception.DefaultExceptionTranslator.translate(DefaultExceptionTranslator.java:47) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:620) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:612) at com.df.test.TaskSplitter.processMessage(TaskSplitter.java:41) at com.df.test.TaskSplitterGigaspacesMethodinternalInvoke2.internalInvoke(Unknown Source) at com.gigaspaces.internal.reflection.fast.AbstractMethod.invoke(AbstractMethod.java:34) at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:172) ... 7 more Caused by: com.gigaspaces.internal.metadata.converter.ConversionException: net.jini.core.entry.UnusableEntryException at com.gigaspaces.internal.transport.EntryPacketFactory.createFullPacket(EntryPacketFactory.java:47) at com.gigaspaces.internal.metadata.PojoIntrospector.toEntryPacket(PojoIntrospector.java:470) at com.gigaspaces.internal.metadata.TypeDesc.toEntryPacket(TypeDesc.java:400) at com.j_spaces.core.client.transport.TypeManager.buildEntryPacket(TypeManager.java:139) at com.j_spaces.core.client.transport.TypeManager.getEntryPacketFromObject(TypeManager.java:565) at com.j_spaces.core.client.transport.TypeManager.getEntryPacketFromObject(TypeManager.java:503) at com.gigaspaces.internal.client.spaceproxy.actions.WriteProxyAction.beforeExecute(WriteProxyAction.java:37) at com.gigaspaces.internal.client.spaceproxy.actions.WriteProxyAction.initialize(WriteProxyAction.java:30) at com.gigaspaces.internal.client.spaceproxy.actions.AbstractSpaceProxyActionManager.write(AbstractSpaceProxyActionManager.java:330) at com.gigaspaces.internal.client.spaceproxy.AbstractSpaceProxy.write(AbstractSpaceProxy.java:414) at org.openspaces.core.DefaultGigaSpace.write(DefaultGigaSpace.java:618) ... 12 more Caused by: net.jini.core.entry.UnusableEntryException at com.gigaspaces.internal.metadata.PojoIntrospector.getValues(PojoIntrospector.java:272) at com.gigaspaces.internal.transport.EntryPacketFactory.createFullPacket(EntryPacketFactory.java:35) ... 22 more Caused by: java.lang.ClassCastException: com.df.test.SubTask cannot be cast to com.df.test.SubTask at com.df.test.SubTaskGigaspacesProperties.getValues(Unknown Source) at com.gigaspaces.internal.metadata.PojoIntrospector.getValues(PojoIntrospector.java:256) ... 23 more

------------------------ PU jars ----------------------- Both have this layout. Very simple.

META-INF/ META-INF/MANIFEST ...(more)

dfilppi gravatar imagedfilppi ( 2009-10-14 12:11:50 -0500 )edit

Do you have getter and setters for all the POJO fields?

Can you post the com.df.test.SubTask ?

Something is wrong with it. There is something missing.

Shay

shay hassidim gravatar imageshay hassidim ( 2009-10-15 00:04:27 -0500 )edit
0

More detail: the first processing unit has no reference to SubTask in the pu.xml, the second one does. If I undeploy the second processing unit, the error goes away. In other words, it appears that the SubTask definition that gets loaded into the space from the second pu.xml is incompatible (different class loader) from the one that get's created with "new" in the first processing unit. So how should I create new instances in the first processing unit. Below I've put the two pu.xmls:

processing unit #1 pu.xml:

<os-core:space id="space" url="/./processorSpace"/>

<!--
    Defines a local Jini transaction manager (will be used for transactional operations with the space).
-->
<os-core:local-tx-manager id="transactionManager" space="space"/>

<!--
    A wrapper bean to the space to provide OpenSpaces simplified space API (built on top of IJSpace/JavaSpace).
-->
<os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/>

<!--
    The processor bean
-->
<bean id="taskProcessor" class="com.df.test.TaskSplitter">
    <property name="space" ref="gigaSpace"/>
    <property name="transactionManager" ref="transactionManager"/>
</bean>

<!--  Feeds tasks to the task splitter -->
<os-events:polling-container id="taskProcessorPollingEventContainer" giga-space="gigaSpace">
    <!--  <os-events:tx-support tx-manager="transactionManager"/> -->
    <os-core:template>
        <bean class="com.df.test.Task">
            <property name="status" value="Initial"/>
        </bean>
    </os-core:template>
    <os-events:listener>
        <os-events:method-adapter method-name="processMessage">
            <os-events:delegate ref="taskProcessor"/>
        </os-events:method-adapter>
    </os-events:listener>
</os-events:polling-container>

processing unit #2 pu.xml :

<!--
    A bean representing a space (an IJSpace implementation).
-->
<os-core:space id="space" url="/./processorSpace" />

<!--
    Defines a local Jini transaction manager (will be used for transactional operations with the space).
-->
<os-core:local-tx-manager id="transactionManager" space="space"/>

<!--
    A wrapper bean to the space to provide OpenSpaces simplified space API (built on top of IJSpace/JavaSpace).
-->
<os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/>


<bean id="scriptCache" class="com.df.test.ScriptCache"/>

<bean id="scriptRunner" class="com.df.test.ScriptRunner">
    <property name="space" ref="gigaSpace"/>
    <property name="scriptCache" ref="scriptCache"/>
</bean>


<!--  Feeds subtasks to the script runner -->
<os-events:polling-container id="scriptRunnerPollingEventContainer" giga-space="gigaSpace">
    <os-events:tx-support tx-manager="transactionManager"/>
    <os-core:template>
        <bean class="com.df.test.SubTask">
            <property name="status" value="Initial"/>
        </bean>
    </os-core:template>
    <os-events:listener>
        <os-events:method-adapter method-name="execute">
            <os-events:delegate ref="scriptRunner"/>
        </os-events:method-adapter>
    </os-events:listener>
</os-events:polling-container>

answered 2009-10-16 10:22:26 -0500

edit flag offensive delete link more
0

The project runs if everything is in a single PU. Does that help? The code is below:

package com.df.test;

import java.util.Date;

public class SubTask { /** * */

private Date startTime=null;
private Date endTime=null;
private Integer stockId=null;
private String script=null;
private Double result=null;
private State status=null;
private Long parentTask=null;
private Boolean processed=null;

public SubTask(){}

public SubTask(Long parentId, Date st,Date et,Integer sid, String script){
    this.startTime=st;
    this.endTime=et;
    this.stockId=sid;
    this.script=script;
    this.parentTask=parentId;
    this.status=State.Initial;
    this.processed=false;
}

public Date getStartTime() {
    return startTime;
}
public void setStartTime(Date startTime) {
    this.startTime = startTime;
}
public Date getEndTime() {
    return endTime;
}
public void setEndTime(Date endTime) {
    this.endTime = endTime;
}
public Integer getStockId() {
    return stockId;
}
public void setStockId(Integer stockId) {
    this.stockId = stockId;
}
public String getScript() {
    return script;
}
public void setScript(String script) {
    this.script = script;
}

public Double getResult() {
    return result;
}

public void setResult(Double result) {
    this.result = result;
}

public Long getParentTask() {
    return parentTask;
}

public void setParentTask(Long parentTask) {
    this.parentTask = parentTask;
}

public static enum State{       
    Initial,
    Success,
    Error;

    private Integer id=null;



}

public State getStatus() {
    return status;
}

public void setStatus(State status) {
    this.status = status;
    if(status!=null && status!=State.Initial){
        processed=true;
    }
}

public Boolean getProcessed() {
    return processed;
}

public void setProcessed(Boolean processed) {
    this.processed = processed;
}

}

answered 2009-10-15 09:04:41 -0500

edit flag offensive delete link more
0

More info: I got rid of the polling event container, and basically wrote my own be responding to Spring lifecycle events. So when the first PU is deployed, no SubTask appears in the space (since it is only created in response to detecting a Task object). When the second PU is deployed, the SubTask appears in the space, because a blocking "take" immediately begins. Now when PU 1 put a SubTask in the space, the class cast exception still occurs. This happens no matter where the common code resides ( I tried pretty much every folder in lib ).

In summary, getting rid of the polling event container had no effect, and clearly I've got class loader problems.

answered 2009-10-16 16:58:46 -0500

edit flag offensive delete link more

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: 2009-10-14 10:17:51 -0500

Seen: 59 times

Last updated: Oct 16 '09