
io.jsync.AsyncFactory Maven / Gradle / Ivy
Show all versions of jsync.io Show documentation
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.jsync;
import java.util.ServiceLoader;
/**
* Factory for creating Async instances.
*
* @author pidster
*/
public abstract class AsyncFactory {
/**
* Create a non clustered Async instance
*/
public static Async newAsync() {
return loadFactory().createAsync();
}
/**
* Create a clustered Async instance listening for cluster connections on the default port 25500
*
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Async newAsync(String hostname) {
return loadFactory().createAsync(hostname);
}
/**
* Create a clustered Async instance.
* Note that the event bus might not be listening until some time after this method has returned
*
* @param port The port to listen for cluster connections
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Async newAsync(int port, String hostname) {
return loadFactory().createAsync(port, hostname);
}
/**
* Create a clustered Async instance returning the instance asynchronously in the resultHandler
* when the event bus is ready and listening
*
* @param port The port to listen for cluster connections
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static void newAsync(int port, String hostname, Handler> resultHandler) {
loadFactory().createAsync(port, hostname, resultHandler);
}
private static AsyncFactory loadFactory() {
ServiceLoader factories = ServiceLoader.load(AsyncFactory.class);
return factories.iterator().next();
}
protected Async createAsync() {
return null;
}
protected Async createAsync(String hostname) {
return null;
}
protected Async createAsync(int port, String hostname) {
return null;
}
protected void createAsync(int port, String hostname, Handler> resultHandler) {
}
}