Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cometd.javascript;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The thread model object, that runs all javascript in a single thread to simulate browser's environment.
*/
public class JavaScriptThreadModel extends ScriptableObject implements Runnable, ThreadModel {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Thread thread = new Thread(this);
private final BlockingQueue> queue = new LinkedBlockingQueue<>();
private final ScriptableObject rootScope;
private volatile boolean running;
private volatile Context context;
private AtomicInteger scripts = new AtomicInteger();
public JavaScriptThreadModel() {
this(null);
}
public JavaScriptThreadModel(ScriptableObject rootScope) {
this.rootScope = rootScope;
}
public void init() throws Exception {
assert rootScope != null;
queue.clear();
running = true;
thread.start();
}
public void destroy() throws Exception {
running = false;
for (FutureTask