本文整理汇总了Java中org.jetbrains.jps.service.SharedThreadPool类的典型用法代码示例。如果您正苦于以下问题:Java SharedThreadPool类的具体用法?Java SharedThreadPool怎么用?Java SharedThreadPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharedThreadPool类属于org.jetbrains.jps.service包,在下文中一共展示了SharedThreadPool类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureJavacServerStarted
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
private static synchronized ExternalJavacManager ensureJavacServerStarted(@NotNull CompileContext context) throws Exception {
ExternalJavacManager server = ExternalJavacManager.KEY.get(context);
if (server != null) {
return server;
}
final int listenPort = findFreePort();
server = new ExternalJavacManager(Utils.getSystemRoot()) {
protected ExternalJavacProcessHandler createProcessHandler(Process process) {
return new ExternalJavacProcessHandler(process) {
protected Future<?> executeOnPooledThread(Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
};
}
};
server.start(listenPort);
ExternalJavacManager.KEY.set(context, server);
return server;
}
示例2: ExternalJavacProcess
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
public ExternalJavacProcess() {
final JavacRemoteProto.Message msgDefaultInstance = JavacRemoteProto.Message.getDefaultInstance();
myEventLoopGroup = new NioEventLoopGroup(1, SharedThreadPool.getInstance());
myChannelInitializer = new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new ProtobufVarint32FrameDecoder(),
new ProtobufDecoder(msgDefaultInstance),
new ProtobufVarint32LengthFieldPrepender(),
new ProtobufEncoder(),
new CompilationRequestsHandler()
);
}
};
}
示例3: JavacServer
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
public JavacServer() {
myChannelFactory = new NioServerSocketChannelFactory(SharedThreadPool.getInstance(), SharedThreadPool.getInstance(), 1);
final ChannelRegistrar channelRegistrar = new ChannelRegistrar();
final ChannelHandler compilationRequestsHandler = new CompilationRequestsHandler();
myPipelineFactory = new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
channelRegistrar,
new ProtobufVarint32FrameDecoder(),
new ProtobufDecoder(JavacRemoteProto.Message.getDefaultInstance()),
new ProtobufVarint32LengthFieldPrepender(),
new ProtobufEncoder(),
compilationRequestsHandler
);
}
};
}
示例4: createModuleLevelBuilders
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
@NotNull
@Override
public List<? extends ModuleLevelBuilder> createModuleLevelBuilders() {
return Arrays.asList(new JavaBuilder(SharedThreadPool.getInstance()),
new NotNullInstrumentingBuilder(),
new RmiStubsGenerator(),
new ClassFilesIndicesBuilder());
}
示例5: JavacServerClient
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
public JavacServerClient() {
super(JavacRemoteProto.Message.getDefaultInstance(), SharedThreadPool.getInstance(), new UUIDGetter() {
@NotNull
public UUID getSessionUUID(@NotNull MessageEvent e) {
final JavacRemoteProto.Message message = (JavacRemoteProto.Message)e.getMessage();
final JavacRemoteProto.Message.UUID uuid = message.getSessionId();
return new UUID(uuid.getMostSigBits(), uuid.getLeastSigBits());
}
});
}
示例6: channelRead0
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
@Override
public void channelRead0(final ChannelHandlerContext context, JavacRemoteProto.Message message) throws Exception {
final UUID sessionId = JavacProtoUtil.fromProtoUUID(message.getSessionId());
final JavacRemoteProto.Message.Type messageType = message.getMessageType();
JavacRemoteProto.Message reply = null;
try {
if (messageType == JavacRemoteProto.Message.Type.REQUEST) {
final JavacRemoteProto.Message.Request request = message.getRequest();
final JavacRemoteProto.Message.Request.Type requestType = request.getRequestType();
if (requestType == JavacRemoteProto.Message.Request.Type.COMPILE) {
if (myCancelHandler == null) { // if not running yet
final List<String> options = request.getOptionList();
final List<File> files = toFiles(request.getFileList());
final List<File> cp = toFiles(request.getClasspathList());
final List<File> platformCp = toFiles(request.getPlatformClasspathList());
final List<File> srcPath = toFiles(request.getSourcepathList());
final Map<File, Set<File>> outs = new HashMap<File, Set<File>>();
for (JavacRemoteProto.Message.Request.OutputGroup outputGroup : request.getOutputList()) {
final Set<File> srcRoots = new HashSet<File>();
for (String root : outputGroup.getSourceRootList()) {
srcRoots.add(new File(root));
}
outs.put(new File(outputGroup.getOutputRoot()), srcRoots);
}
final CancelHandler cancelHandler = new CancelHandler();
myCancelHandler = cancelHandler;
SharedThreadPool.getInstance().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
context.channel().writeAndFlush(
compile(context, sessionId, options, files, cp, platformCp, srcPath, outs, cancelHandler)
).awaitUninterruptibly();
}
finally {
myCancelHandler = null;
ExternalJavacProcess.this.stop();
}
}
});
}
}
else if (requestType == JavacRemoteProto.Message.Request.Type.CANCEL){
cancelBuild();
}
else if (requestType == JavacRemoteProto.Message.Request.Type.SHUTDOWN){
cancelBuild();
new Thread("StopThread") {
@Override
public void run() {
//noinspection finally
ExternalJavacProcess.this.stop();
}
}.start();
}
else {
reply = JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createFailure("Unsupported request type: " + requestType.name(), null));
}
}
else {
reply = JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createFailure("Unsupported message: " + messageType.name(), null));
}
}
finally {
if (reply != null) {
context.channel().writeAndFlush(reply);
}
}
}
示例7: EventsProcessor
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
EventsProcessor() {
super(SharedThreadPool.getInstance());
}
示例8: run
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
@Override
public Future<?> run(Runnable runnable) {
return SharedThreadPool.getInstance().executeOnPooledThread(runnable);
}
示例9: runGroovyc
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
@Override
public GroovycContinuation runGroovyc(Collection<String> compilationClassPath,
boolean forStubs,
JpsGroovySettings settings,
File tempFile,
final GroovycOutputParser parser)
throws Exception {
List<String> classpath = new ArrayList<String>();
if (myOptimizeClassLoading) {
classpath.addAll(GroovyBuilder.getGroovyRtRoots());
classpath.add(ClasspathBootstrap.getResourcePath(Function.class));
classpath.add(ClasspathBootstrap.getResourcePath(UrlClassLoader.class));
classpath.add(ClasspathBootstrap.getResourceFile(THashMap.class).getPath());
} else {
classpath.addAll(compilationClassPath);
}
List<String> vmParams = ContainerUtilRt.newArrayList();
vmParams.add("-Xmx" + System.getProperty("groovyc.heap.size", settings.heapSize) + "m");
vmParams.add("-Dfile.encoding=" + System.getProperty("file.encoding"));
//vmParams.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");
if ("false".equals(System.getProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY))) {
vmParams.add("-D" + GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY + "=false");
}
String configScript = settings.configScript;
if (StringUtil.isNotEmpty(configScript)) {
vmParams.add("-D" + GroovyRtConstants.GROOVYC_CONFIG_SCRIPT + "=" + configScript);
}
String grapeRoot = System.getProperty(GroovycOutputParser.GRAPE_ROOT);
if (grapeRoot != null) {
vmParams.add("-D" + GroovycOutputParser.GRAPE_ROOT + "=" + grapeRoot);
}
final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(
getJavaExecutable(myChunk),
"org.jetbrains.groovy.compiler.rt.GroovycRunner",
Collections.<String>emptyList(), classpath,
vmParams,
getProgramParams(tempFile, settings, forStubs)
);
final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
ProcessHandler handler = new BaseOSProcessHandler(process, null, null) {
@Override
protected Future<?> executeOnPooledThread(Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
@Override
public void notifyTextAvailable(String text, Key outputType) {
parser.notifyTextAvailable(text, outputType);
}
};
handler.startNotify();
handler.waitFor();
parser.notifyFinished(process.exitValue());
return null;
}
示例10: createModuleLevelBuilders
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
@NotNull
@Override
public List<? extends ModuleLevelBuilder> createModuleLevelBuilders() {
return Arrays.asList(new JavaBuilder(SharedThreadPool.getInstance()), new NotNullInstrumentingBuilder(), new RmiStubsGenerator());
}
示例11: messageReceived
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
final JavacRemoteProto.Message msg = (JavacRemoteProto.Message)e.getMessage();
final UUID sessionId = JavacProtoUtil.fromProtoUUID(msg.getSessionId());
final JavacRemoteProto.Message.Type messageType = msg.getMessageType();
JavacRemoteProto.Message reply = null;
try {
if (messageType == JavacRemoteProto.Message.Type.REQUEST) {
final JavacRemoteProto.Message.Request request = msg.getRequest();
final JavacRemoteProto.Message.Request.Type requestType = request.getRequestType();
if (requestType == JavacRemoteProto.Message.Request.Type.COMPILE) {
final List<String> options = request.getOptionList();
final List<File> files = toFiles(request.getFileList());
final List<File> cp = toFiles(request.getClasspathList());
final List<File> platformCp = toFiles(request.getPlatformClasspathList());
final List<File> srcPath = toFiles(request.getSourcepathList());
final Map<File, Set<File>> outs = new HashMap<File, Set<File>>();
for (JavacRemoteProto.Message.Request.OutputGroup outputGroup : request.getOutputList()) {
final Set<File> srcRoots = new HashSet<File>();
for (String root : outputGroup.getSourceRootList()) {
srcRoots.add(new File(root));
}
outs.put(new File(outputGroup.getOutputRoot()), srcRoots);
}
final CancelHandler cancelHandler = new CancelHandler();
myCancelHandlers.add(cancelHandler);
SharedThreadPool.getInstance().executeOnPooledThread(new Runnable() {
public void run() {
try {
final JavacRemoteProto.Message exitMsg =
compile(ctx, sessionId, options, files, cp, platformCp, srcPath, outs, cancelHandler);
Channels.write(ctx.getChannel(), exitMsg);
}
finally {
myCancelHandlers.remove(cancelHandler);
}
}
});
}
else if (requestType == JavacRemoteProto.Message.Request.Type.CANCEL){
cancelBuilds();
reply = JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createRequestAckResponse());
}
else if (requestType == JavacRemoteProto.Message.Request.Type.SHUTDOWN){
cancelBuilds();
new Thread("StopThread") {
public void run() {
try {
JavacServer.this.stop();
}
finally {
System.exit(0);
}
}
}.start();
}
else {
reply = JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createFailure("Unsupported request type: " + requestType.name(), null));
}
}
else {
reply = JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createFailure("Unsupported message: " + messageType.name(), null));
}
}
finally {
if (reply != null) {
Channels.write(ctx.getChannel(), reply);
}
}
}
示例12: main
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
public static void main(String[] args){
System.out.println("Build process started. Classpath: " + System.getProperty("java.class.path"));
final String host = args[0];
final int port = Integer.parseInt(args[1]);
final UUID sessionId = UUID.fromString(args[2]);
final File systemDir = new File(FileUtil.toCanonicalPath(args[3]));
Utils.setSystemRoot(systemDir);
ourChannelFactory = new NioClientSocketChannelFactory(SharedThreadPool.getInstance(), SharedThreadPool.getInstance(), 1);
final ClientBootstrap bootstrap = new ClientBootstrap(ourChannelFactory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
new ProtobufVarint32FrameDecoder(),
new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()),
new ProtobufVarint32LengthFieldPrepender(),
new ProtobufEncoder(),
new MyMessageHandler(sessionId)
);
}
});
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
final ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
future.awaitUninterruptibly();
final boolean success = future.isSuccess();
if (success) {
Channels.write(future.getChannel(), CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createParamRequest()));
}
else {
final Throwable reason = future.getCause();
System.err.println("Error connecting to " + host + ":" + port + "; reason: " + (reason != null? reason.getMessage() : "unknown"));
if (reason != null) {
reason.printStackTrace(System.err);
}
System.err.println("Exiting.");
System.exit(-1);
}
}
示例13: runGroovyc
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
private GroovycOSProcessHandler runGroovyc(final CompileContext context,
ModuleChunk chunk,
File tempFile,
final JpsGroovySettings settings) throws IOException {
ArrayList<String> classpath = new ArrayList<String>(generateClasspath(context, chunk));
if (LOG.isDebugEnabled()) {
LOG.debug("Groovyc classpath: " + classpath);
}
List<String> programParams = ContainerUtilRt.newArrayList(myForStubs ? "stubs" : "groovyc", tempFile.getPath());
if (settings.invokeDynamic) {
programParams.add("--indy");
}
List<String> vmParams = ContainerUtilRt.newArrayList();
vmParams.add("-Xmx" + settings.heapSize + "m");
vmParams.add("-Dfile.encoding=" + System.getProperty("file.encoding"));
//vmParams.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");
String grapeRoot = System.getProperty(GroovycOSProcessHandler.GRAPE_ROOT);
if (grapeRoot != null) {
vmParams.add("-D" + GroovycOSProcessHandler.GRAPE_ROOT + "=" + grapeRoot);
}
final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(
getJavaExecutable(chunk),
"org.jetbrains.groovy.compiler.rt.GroovycRunner",
Collections.<String>emptyList(), classpath,
vmParams,
programParams
);
final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
final Consumer<String> updater = new Consumer<String>() {
public void consume(String s) {
context.processMessage(new ProgressMessage(s));
}
};
final GroovycOSProcessHandler handler = new GroovycOSProcessHandler(process, updater) {
@Override
protected Future<?> executeOnPooledThread(Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
};
handler.startNotify();
handler.waitFor();
return handler;
}
示例14: run
import org.jetbrains.jps.service.SharedThreadPool; //导入依赖的package包/类
/**
* Runs {@link IgnoreLanguage} executable with the given command and current working directory.
*
* @param language current language
* @param command to call
* @param directory current working directory
* @param parser {@link ExecutionOutputParser} implementation
* @param <T> return type
* @return result of the call
*/
@Nullable
private static <T> ArrayList<T> run(@NotNull IgnoreLanguage language,
@NotNull String command,
@Nullable VirtualFile directory,
@Nullable final ExecutionOutputParser<T> parser) {
final String bin = bin(language);
if (bin == null) {
return null;
}
try {
final String cmd = bin + " " + command;
final File workingDirectory = directory != null ? new File(directory.getPath()) : null;
final Process process = Runtime.getRuntime().exec(cmd, null, workingDirectory);
ProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmd, " "), null) {
@NotNull
@Override
protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
@Override
public void notifyTextAvailable(String text, Key outputType) {
if (parser != null) {
parser.onTextAvailable(text, outputType);
}
}
};
handler.startNotify();
if (!handler.waitFor(DEFAULT_TIMEOUT)) {
return null;
}
if (parser != null) {
parser.notifyFinished(process.exitValue());
if (parser.isErrorsReported()) {
return null;
}
return parser.getOutput();
}
} catch (IOException ignored) {
}
return null;
}