Search in sources :

Example 1 with FolderRequestHandler

use of org.syncany.operations.daemon.messages.api.FolderRequestHandler 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)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 File (java.io.File)1 ConfigException (org.syncany.config.ConfigException)1 AlreadySyncingResponse (org.syncany.operations.daemon.messages.AlreadySyncingResponse)1 BadRequestResponse (org.syncany.operations.daemon.messages.BadRequestResponse)1 FolderRequestHandler (org.syncany.operations.daemon.messages.api.FolderRequestHandler)1 Response (org.syncany.operations.daemon.messages.api.Response)1