Not able to create custom Predicate while using fast aggregations in Hazelcast - java

I am creating a custom Predicate. It takes an integer and compares it with the value of map.
public class LocationPredicate implements Predicate<Key, Portable> {
private int rssi;
public LocationPredicate() {
}
public LocationPredicate(int rssi) {
this.rssi = rssi;
}
#Override
public boolean apply(Entry<Key, Aortable> arg0) {
return false;
//int val = arg0.getValue().getData().getLocation().getRssiVal();
//return (rssi == val ) ;
}
}
When I run the program, I am getting the following error:
Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.snmpapp.main.LocationPredicate
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
at ------ submitted from ------.(Unknown Source)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:95)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:32)
at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155)
at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:172)
at com.hazelcast.client.proxy.ClientMapProxy.aggregate(ClientMapProxy.java:1356)
at com.snmpapp.main.Main.main(Main.java:370)
Caused by: java.lang.ClassNotFoundException: com.aruba.acp.snmpapp.main.LocationPredicate
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149)
at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123)
at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
I am little bit confused. Do I need to create the Predicate on the server? I am running as Hcast client and the client is creating the predicate.
As far as I know, when you create the predicate, it is sent as a serialized object to the hazelcast server.
Also, I tried to implement Predicate as Serializable, but it didnt help.
Thanks

I am not experienced with Hazelcast but as far as I know during serialisation and deserialisation you can transfer state (in this case the member variable) but not the behaviour (your actual implementation of apply method). Somehow (I am not experienced with this technology) you should provide your class to the Hazelcast's class loader (maybe copying to the classpath). Good luck!

The class needs to be on the classpath of all nodes.

Related

ResourceAwareScheduler is not found in Storm 2.1.0

I am using Storm 2.1.0 and would like to use the Resource Aware Scheduler. I followed instructions from the documentation and added the following line to my conf/storm.yaml:
storm.scheduler: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
But when I execute ./bin/storm nimbus it crashes and I can see the following log in logs/nimbus.log:
2020-06-25 16:02:09.962 o.a.s.d.n.Nimbus main [INFO] Using custom scheduler: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
2020-06-25 16:02:09.963 o.a.s.u.Utils main [ERROR] Received error in thread main.. terminating server...
java.lang.Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
at org.apache.storm.utils.Utils.handleUncaughtException(Utils.java:653) ~[storm-client-2.1.0.jar:2.1.0]
at org.apache.storm.utils.Utils.handleUncaughtException(Utils.java:632) ~[storm-client-2.1.0.jar:2.1.0]
at org.apache.storm.utils.Utils.lambda$createDefaultUncaughtExceptionHandler$2(Utils.java:1014) ~[storm-client-2.1.0.jar:2.1.0]
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1057) [?:1.8.0_252]
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1052) [?:1.8.0_252]
at java.lang.Thread.dispatchUncaughtException(Thread.java:1959) [?:1.8.0_252]
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
at org.apache.storm.utils.ReflectionUtils.newInstance(ReflectionUtils.java:48) ~[storm-client-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.makeScheduler(Nimbus.java:658) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:569) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:474) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:468) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.launchServer(Nimbus.java:1307) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.launch(Nimbus.java:1332) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.main(Nimbus.java:1337) ~[storm-server-2.1.0.jar:2.1.0]
Caused by: java.lang.ClassNotFoundException: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_252]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_252]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) ~[?:1.8.0_252]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_252]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_252]
at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_252]
at org.apache.storm.utils.ReflectionUtils.newInstance(ReflectionUtils.java:46) ~[storm-client-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.makeScheduler(Nimbus.java:658) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:569) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:474) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.<init>(Nimbus.java:468) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.launchServer(Nimbus.java:1307) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.launch(Nimbus.java:1332) ~[storm-server-2.1.0.jar:2.1.0]
at org.apache.storm.daemon.nimbus.Nimbus.main(Nimbus.java:1337) ~[storm-server-2.1.0.jar:2.1.0]
I understand that the class is not found but wasn't expecting this. I just downloaded the latest version of Storm from their official website (binary version), I checked on the source code if the class exists (it does), Zookeeper is up and running, and I followed the given instruction to enable this scheduler. I probably forgot something but I totally don't know what.
But anyway, let's continue this investigation. In Nimbus.java it initializes the scheduler:
private static IScheduler makeScheduler(Map<String, Object> conf, INimbus inimbus) {
String schedClass = (String) conf.get(DaemonConfig.STORM_SCHEDULER);
IScheduler scheduler = inimbus == null ? null : inimbus.getForcedScheduler();
if (scheduler != null) {
LOG.info("Using forced scheduler from INimbus {} {}", scheduler.getClass(), scheduler);
} else if (schedClass != null) {
LOG.info("Using custom scheduler: {}", schedClass);
scheduler = ReflectionUtils.newInstance(schedClass);
} else {
LOG.info("Using default scheduler");
scheduler = new DefaultScheduler();
}
return scheduler;
}
The following log tells me that it's trying to get the correct scheduler:
... Nimbus main [INFO] Using custom scheduler: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
An then, it calls ReflectionUtils.newInstance() which is implemented in ReflectionUtils.java:
public static <T> T newInstance(String klass) {
try {
return newInstance((Class<T>) Class.forName(klass));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Exception seems to be raised from here because it is not able to find the class ResourceAwareScheduler. I double checked and the class exist at the given location. At this stage I got to admit that it reaches my knowledge of Java. Am I suppose to manually import this class in ReflectionUtils.java? It has the full path to the class, so I suppose it is not necessary. How should I configure this Maven project to include this class?
Any help with this will be gladly appreciated.
I finally found the problem. There is a difference between:
storm.scheduler: “org.apache.storm.scheduler.resource.ResourceAwareScheduler”
and
storm.scheduler: "org.apache.storm.scheduler.resource.ResourceAwareScheduler"
Even the highlighting for code from StackOverflow should have helped me. I feel stupid. It's a gentle reminder that copy-pasting, even from official documentation, is bad! Hope this will help other bros.

Caused by: java.lang.UnsupportedOperationException: BigQuery source must be split before being read

I am trying to read from bigquery using Java BigqueryIO.read method. but getting below error.
public POutput expand(PBegin pBegin) {
final String queryOperation = "select query";
return pBegin
.apply(BigQueryIO.readTableRows().fromQuery(queryOperation));
}
2020-06-08 19:32:01.391 ISTError message from worker: java.io.IOException: Failed to start reading from source: org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource$BoundedToUnboundedSourceAdapter#77f0db34 org.apache.beam.runners.dataflow.worker.WorkerCustomSources$UnboundedReaderIterator.start(WorkerCustomSources.java:792) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation$SynchronizedReaderIterator.start(ReadOperation.java:361) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:194) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.start(ReadOperation.java:159) org.apache.beam.runners.dataflow.worker.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:77) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:1320) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.access$1000(StreamingDataflowWorker.java:151) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:1053) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:748) Caused by: java.lang.UnsupportedOperationException: BigQuery source must be split before being read org.apache.beam.sdk.io.gcp.bigquery.BigQuerySourceBase.createReader(BigQuerySourceBase.java:173) org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource$BoundedToUnboundedSourceAdapter$ResidualSource.advance(UnboundedReadFromBoundedSource.java:467) org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource$BoundedToUnboundedSourceAdapter$ResidualSource.access$300(UnboundedReadFromBoundedSource.java:446) org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource$BoundedToUnboundedSourceAdapter$Reader.advance(UnboundedReadFromBoundedSource.java:298) org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource$BoundedToUnboundedSourceAdapter$Reader.start(UnboundedReadFromBoundedSource.java:291) org.apache.beam.runners.dataflow.worker.WorkerCustomSources$UnboundedReaderIterator.start(WorkerCustomSources.java:787) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation$SynchronizedReaderIterator.start(ReadOperation.java:361) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:194) org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.start(ReadOperation.java:159) org.apache.beam.runners.dataflow.worker.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:77) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:1320) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.access$1000(StreamingDataflowWorker.java:151) org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:1053) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:748)
I suppose that this issue might be connected with missing tempLocation pipeline execution parameter when you are using DataflowRunner for cloud execution.
According to the documentation:
If tempLocation is not specified and gcpTempLocation is, tempLocation will not be populated.
Since this is just my presumption, I'll also encourage you to inspect native Apache Beam runtime logs to expand the overall issue evidence, as long as Stackdriver logs don't reflect a full picture of the problem.
There was raised a separate Jira tracker thread BEAM-9043, indicating this vaguely outputted error description.
Feel free to append more certain information to you origin question for any further concern or essential updates.

spring-data-couchbase throws DocumentDoesNotExistException for non-existent documents

I am using spring-data-couchbase 2.1.2 with spring-boot 1.4.0.RC1 and couchbase-spring-cache
It works fine when caching is disabled as it returns NULL object When caching is enabled and try to find a non-existing document in the bucket it throws an exception:
com.couchbase.client.java.error.DocumentDoesNotExistException: null
at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:684) ~[java-client-2.2.8.jar:na]
at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:671) ~[java-client-2.2.8.jar:na]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) ~[rxjava-1.0.17.jar:1.0.17]
at rx.observers.Subscribers$5.onNext(Subscribers.java:234) ~[rxjava-1.0.17.jar:1.0.17]
at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onNext(SubjectSubscriptionManager.java:223) ~[rxjava-1.0.17.jar:1.0.17]
at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:101) ~[rxjava-1.0.17.jar:1.0.17]
at com.couchbase.client.core.endpoint.AbstractGenericHandler.completeResponse(AbstractGenericHandler.java:354) ~[core-io-1.2.9.jar:na]
at com.couchbase.client.core.endpoint.AbstractGenericHandler.access$000(AbstractGenericHandler.java:72) ~[core-io-1.2.9.jar:na]
at com.couchbase.client.core.endpoint.AbstractGenericHandler$1.call(AbstractGenericHandler.java:372) ~[core-io-1.2.9.jar:na]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) ~[rxjava-1.0.17.jar:1.0.17]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_80]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) ~[na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) ~[na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) ~[na:1.7.0_80]
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.core.message.kv.RemoveResponse.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:109) ~[rxjava-1.0.17.jar:1.0.17]
at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:188) ~[rxjava-1.0.17.jar:1.0.17]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:56) ~[rxjava-1.0.17.jar:1.0.17]
... 14 common frames omitted
Is it because of AsyncBucket? Is it possible to disable AsyncBucket?
Source code https://github.com/maverickmicky/spring-couchbase-cache
This is an issue indeed... As soon as an eviction attempt for a key that isn't in cache is made, the exception will be thrown :(
I've created an issue for this (with work arounds).
edit: To work around the issue, you should be able to declare a CacheErrorHandler that has a handleCacheEvictError method that simply catches DocumentDoesNotExistException.
See the documentation section on configuring the cache abstraction here and the CachingConfigurer javadoc.
I am across the same exception and use case is I am caching the resource which return null, for example:
#Override
#Cacheable(value = "EMPLOYEE_", key = "#id")
public Employee getEmployee(int id) {
return null;
}
And fixed it using the unless attribute of #Cacheable which is available as of Spring 3.2, as follows:
#Override
#Cacheable(value = "EMPLOYEE_", key = "#id", unless = "#result == null")
public Employee getEmployee(int id) {
return null;
}
Have written an article as well which describe my problem and fix for the same - Fixing com.couchbase.client.java.error.DocumentDoesNotExistException – Couchbase

Remote call a webcam in Java

So I'm fiddling about with webcam usage in Java. I have tried using this set of libraries found here: https://github.com/sarxos/webcam-capture
All the examples seem to work and I can call webcam opening from other classes as well. However, my current setup I'm using includes a webapp hosted on a Tomcat server in Eclipse EE. When a button is pressed it sends a message to the server and does the according command based on the message.
The problem is that when a message is send to open the camera I get this error:
java.lang.RuntimeException: com/github/sarxos/webcam/WebcamPanel
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerBase.handlePojoMethodException(PojoMessageHandlerBase.java:119)
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerWholeBase.onMessage(PojoMessageHandlerWholeBase.java:82)
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:393)
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:494)
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:289)
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/github/sarxos/webcam/WebcamPanel
at WebcamPanelExample.handleMessage(WebcamPanelExample.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerWholeBase.onMessage(PojoMessageHandlerWholeBase.java:80)
... 16 more
Caused by: java.lang.ClassNotFoundException: com.github.sarxos.webcam.WebcamPanel
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
... 22 more
If I create a main method to open the camera it seems to work fine, but when I want to call it from from the message handler it doesn't. Is there something obvious I am missing?
Thanks in advance!
Doesn't work:
#OnMessage
public void handleMessage(String message) throws IOException {
if(message.equals("Camera"))
{
CameraTest.OpenCam1(); // Method that opens camera
}
}
Works:
public static void main(String[] args) {
CameraTest.OpenCam();
}

java RMI - unexpected error

I have been working on to create a sample RMI project for a while and having difficulty with the following error for a few hours now. If anyone of you can point me towards my mistake, I will be grateful. I will be posting the trimmed code with the error.
Thanks in advance for your time.
PrimeFinder.java
import //irrelevant
public interface PrimeFinder extends Remote
{
public List<Integer> findPrime (int startPoint, int endPoint )
throws RemoteException;
}
PrimeFinderService.java
import //irrelevant
public class PrimeFinderService extends UnicastRemoteObject
implements PrimeFinder
{
public PrimeFinderService () throws RemoteException
{
super();
}
public List<Integer> findPrime(int startPoint, int endPoint)
throws RemoteException {
// Irrelevant
}
public static void main ( String args[] ) throws Exception
{
if (System.getSecurityManager() == null)
System.setSecurityManager ( new RMISecurityManager() );
PrimeFinderService svr = new PrimeFinderService();
Naming.bind ("PowerService", svr);
System.out.println ("Service bound....");
}
}
.policy
grant {
permission java.security.AllPermission; }
The error that is killing me :
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Naming.java:128)
at q7.PrimeFinderService.main(PrimeFinderService.java:69)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:445)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:182)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:214)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1592)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1513)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
... 12 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
at java.security.AccessController.checkPermission(AccessController.java:553)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at sun.rmi.server.LoaderHandler$Loader.checkPermissions(LoaderHandler.java:1173)
at sun.rmi.server.LoaderHandler$Loader.access$000(LoaderHandler.java:1127)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:409)
... 21 more
Edit 1:
The error line that I'm trying to overcome is:
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)
I have tried at least 10 different approaches in my .policy file - all of which ended up with the same problem. I have tried anything in the tutorials I have found and it's I believe safe to say that the problem doesn't lie in .policy file.
I have also meddled with the codebase, giving the codebase wrong ends up with different errors so that can't be it either.
Still looking for ideas ^^
Cheers !
Get rid of the SecurityManager, or else write yourself a security policy file that grants that permission.
The problem was regarding linux file system permissions, altering permissions fixes the problem.
If someone stumbles upon the issue on Windows, then two words... Windows Defender. It probably just deleted your project files.
So just rebuild your project. No not "build", just entirely "rebuild".
Windows Defender might delete your project' executables if they went into high CPU usage. So I also always suggest putting your project' directory as an exception.

Categories