1

I am trying to execute some code on a member node of an infinispan cluster but I'm getting the same error all the time.

org.infinispan.commons.marshall.NotSerializableException:

The use case is pretty basic. There's a list of units only the coordinator node knows and wants to distribute some work among its member nodes.

Basically I just want to call a method remotely with my args. That's it, that's all, plain and simple.

private void processUnit(Unit unit)
{
  Processor.process(unit);
}

public void distributeUnits(List<Unit> units)
{
  for (int i = 0; i < units.size(); ++i)
  {
    Address target = getAddress(i);
    ClusterExecutor executor = getExecutor();
    executor.filterTargets(target).submit((Runnable & Serializable) () -> processUnit(unit);
  }
}

My goal would be the member node to execute the Runnable with the node context (its own Processor, which is an @Autowired spring @Component).

I have tried different approaches like statics here and there, classes extending and/or implementing Runnable, Serializable, etc. Last thing I've tried is to use the Observer pattern to instead of calling the Processor to call a static OBSERVABLE.notifyObservers(unit) (which has the Processor added as observer). But I've got the same output, and at this point its just trial and error. I'm out of ideas and I would appreciate some directions or guidelines on this.

p4x
  • 384
  • 1
  • 5
  • 16
  • 1
    The code you showed here will make the Runnable lambda Serializable as you want. However this lambda is capturing and the `unit` instance must also be Serializable. Make sure the Unit class or the implementation thereof is also Serializalable. – Mudokonman Aug 19 '19 at 16:39

1 Answers1

0

As @Mudokonman wrote in his comment, the (Runnable & Serializable) syntax is find, but all the variables captured captured by the lambda must be Serializable as well. This includes the implicit this when the lambda invokes a non-static method.

You can try -Dsun.io.serialization.extendedDebugInfo=true to find exactly which part of your lambda is not serializable.

Dan Berindei
  • 7,054
  • 3
  • 41
  • 48