Search in sources :

Example 1 with ClientCallbacks

use of se.trixon.jota.shared.ClientCallbacks in project java-jotasync by trixon.

the class Server method intiListeners.

private void intiListeners() {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        notifyClientsShutdown();
    }));
    mOptions.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        HashSet<ClientCallbacks> invalidClientCallbacks = new HashSet<>();
        for (ClientCallbacks clientCallback : mClientCallbacks) {
            switch(evt.getKey()) {
                case ServerOptions.KEY_CRON_ACTIVE:
                    {
                        try {
                            clientCallback.onServerEvent(ServerEvent.CRON_CHANGED);
                        } catch (RemoteException ex) {
                            // Add invalid reference for removal
                            invalidClientCallbacks.add(clientCallback);
                        }
                    }
                    break;
            }
        }
        invalidClientCallbacks.stream().forEach((invalidClientCallback) -> {
            // Remove invalid reference
            mClientCallbacks.remove(invalidClientCallback);
        });
    });
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) ClientCallbacks(se.trixon.jota.shared.ClientCallbacks) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet)

Example 2 with ClientCallbacks

use of se.trixon.jota.shared.ClientCallbacks in project java-jotasync by trixon.

the class Server method startJob.

@Override
public void startJob(Job job, boolean dryRun) throws RemoteException {
    Xlog.timedOut(String.format("Job started: %s", job.getName()));
    for (ClientCallbacks clientCallback : mClientCallbacks) {
        clientCallback.onProcessEvent(ProcessEvent.STARTED, job, null, null);
    }
    JobExecutor jobExecutor = new JobExecutor(this, job, dryRun);
    mJobExecutors.put(job.getId(), jobExecutor);
    jobExecutor.start();
}
Also used : ClientCallbacks(se.trixon.jota.shared.ClientCallbacks)

Aggregations

ClientCallbacks (se.trixon.jota.shared.ClientCallbacks)2 RemoteException (java.rmi.RemoteException)1 HashSet (java.util.HashSet)1 PreferenceChangeEvent (java.util.prefs.PreferenceChangeEvent)1