Search in sources :

Example 26 with Subscribe

use of com.google.common.eventbus.Subscribe in project syncany by syncany.

the class WebServer method onGetFileResponseInternal.

@Subscribe
public void onGetFileResponseInternal(GetFileFolderResponseInternal fileResponseInternal) {
    File tempFile = fileResponseInternal.getTempFile();
    GetFileFolderResponse fileResponse = fileResponseInternal.getFileResponse();
    fileTokenTempFileCache.asMap().put(fileResponse.getTempToken(), tempFile);
    eventBus.post(fileResponse);
}
Also used : GetFileFolderResponse(org.syncany.operations.daemon.messages.GetFileFolderResponse) File(java.io.File) Subscribe(com.google.common.eventbus.Subscribe)

Example 27 with Subscribe

use of com.google.common.eventbus.Subscribe in project syncany by syncany.

the class WebServer method onResponse.

@Subscribe
public void onResponse(Response response) {
    try {
        // Send to one or many receivers
        boolean responseWithoutRequest = response.getRequestId() == null || response.getRequestId() <= 0;
        if (responseWithoutRequest) {
            sendBroadcast(response);
        } else {
            HttpServerExchange responseToHttpServerExchange = requestIdRestSocketCache.asMap().get(response.getRequestId());
            WebSocketChannel responseToWebSocketChannel = requestIdWebSocketCache.asMap().get(response.getRequestId());
            if (responseToHttpServerExchange != null) {
                sendTo(responseToHttpServerExchange, response);
            } else if (responseToWebSocketChannel != null) {
                sendTo(responseToWebSocketChannel, response);
            } else {
                logger.log(Level.WARNING, "Cannot send message, because request ID in response is unknown or timed out." + response);
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Cannot send response.", e);
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) Subscribe(com.google.common.eventbus.Subscribe)

Example 28 with Subscribe

use of com.google.common.eventbus.Subscribe in project syncany by syncany.

the class WatchRunner method onRequestReceived.

@Subscribe
public void onRequestReceived(FolderRequest folderRequest) {
    File requestRootFolder = new File(folderRequest.getRoot());
    boolean localDirMatches = requestRootFolder.equals(config.getLocalDir());
    if (localDirMatches) {
        logger.log(Level.INFO, "Received " + folderRequest);
        try {
            if (!watchOperation.isSyncRunning() && !watchOperation.isSyncRequested()) {
                watchOperation.pause();
                FolderRequestHandler handler = FolderRequestHandler.createFolderRequestHandler(folderRequest, config);
                Response response = handler.handleRequest(folderRequest);
                if (response != null) {
                    eventBus.post(response);
                }
                watchOperation.resume();
            } else {
                logger.log(Level.WARNING, "FolderRequest discarded : ", folderRequest);
                eventBus.post(new AlreadySyncingResponse(folderRequest.getId(), "FolderRequest discarded."));
            }
        } catch (Exception e) {
            logger.log(Level.FINE, "Failed to process request", e);
            eventBus.post(new BadRequestResponse(folderRequest.getId(), "Invalid request."));
        }
    }
}
Also used : AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) BadRequestResponse(org.syncany.operations.daemon.messages.BadRequestResponse) Response(org.syncany.operations.daemon.messages.api.Response) FolderRequestHandler(org.syncany.operations.daemon.messages.api.FolderRequestHandler) BadRequestResponse(org.syncany.operations.daemon.messages.BadRequestResponse) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) File(java.io.File) ConfigException(org.syncany.config.ConfigException) Subscribe(com.google.common.eventbus.Subscribe)

Example 29 with Subscribe

use of com.google.common.eventbus.Subscribe in project bazel by bazelbuild.

the class AggregatingTestListener method buildCompleteEvent.

@Subscribe
public void buildCompleteEvent(BuildCompleteEvent event) {
    BuildResult result = event.getResult();
    if (result.wasCatastrophe()) {
        blazeHalted = true;
    }
    buildComplete(result.getActualTargets(), result.getSuccessfulTargets());
}
Also used : BuildResult(com.google.devtools.build.lib.buildtool.BuildResult) Subscribe(com.google.common.eventbus.Subscribe)

Example 30 with Subscribe

use of com.google.common.eventbus.Subscribe in project bazel by bazelbuild.

the class ExperimentalEventHandler method testSummary.

@Subscribe
public synchronized void testSummary(TestSummary summary) {
    stateTracker.testSummary(summary);
    if (testSummaryProvidesNewInformation(summary)) {
        // For failed test, write the failure to the scroll-back buffer immediately
        try {
            clearProgressBar();
            crlf();
            setEventKindColor(EventKind.ERROR);
            terminal.writeString("" + summary.getStatus() + ": ");
            terminal.resetTerminal();
            terminal.writeString(summary.getTarget().getLabel().toString());
            terminal.writeString(" (Summary)");
            crlf();
            for (Path logPath : summary.getFailedLogs()) {
                terminal.writeString("      " + logPath.getPathString());
                crlf();
            }
            if (showProgress && cursorControl) {
                addProgressBar();
            }
            terminal.flush();
        } catch (IOException e) {
            LOG.warning("IO Error writing to output stream: " + e);
        }
    } else {
        refresh();
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) IOException(java.io.IOException) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)115 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)13 EventBus (com.google.common.eventbus.EventBus)11 BuckEventBus (com.facebook.buck.event.BuckEventBus)10 Test (org.junit.Test)10 UPID (com.groupon.mesos.util.UPID)8 Scheduler (org.apache.mesos.Scheduler)8 SchedulerDriver (org.apache.mesos.SchedulerDriver)8 IOException (java.io.IOException)7 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 FakeClock (com.facebook.buck.timing.FakeClock)6 ArrayList (java.util.ArrayList)6 LogRecord (java.util.logging.LogRecord)6 Description (org.junit.runner.Description)6 WatchEvent (java.nio.file.WatchEvent)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)5 EventKey (com.facebook.buck.event.EventKey)4 Action (com.google.devtools.build.lib.actions.Action)4 File (java.io.File)4 UUID (java.util.UUID)4