All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jsync.Async Maven / Gradle / Ivy

There is a newer version: 1.10.13
Show newest version
/*
 * 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 io.jsync.datagram.DatagramSocket;
import io.jsync.datagram.InternetProtocolFamily;
import io.jsync.dns.DnsClient;
import io.jsync.eventbus.EventBus;
import io.jsync.file.FileSystem;
import io.jsync.http.HttpClient;
import io.jsync.http.HttpServer;
import io.jsync.net.NetClient;
import io.jsync.net.NetServer;
import io.jsync.shareddata.SharedData;
import io.jsync.sockjs.SockJSServer;
import io.jsync.spi.Action;
import io.jsync.spi.cluster.ClusterManager;

import java.net.InetSocketAddress;

/**
 * The control centre of the jsync.io API.

* This class acts as a factory for TCP/SSL and HTTP/HTTPS servers and clients, SockJS servers, and provides an * instance of the event bus, file system and shared data classes, as well as methods for setting and cancelling * timers.

* Instances of this class are thread-safe.

* * @author Tim Fox */ public interface Async { /** * Create a TCP/SSL server */ NetServer createNetServer(); /** * Create a TCP/SSL client */ NetClient createNetClient(); /** * Create an HTTP/HTTPS server */ HttpServer createHttpServer(); /** * Create a HTTP/HTTPS client */ HttpClient createHttpClient(); /** * Create a new {@link DatagramSocket}. * * @param family use {@link InternetProtocolFamily} to use for multicast. If {@code null} is used it's up to the * operation system to detect it's default. * @return socket the created {@link DatagramSocket}. */ DatagramSocket createDatagramSocket(InternetProtocolFamily family); /** * Create a SockJS server that wraps an HTTP server */ SockJSServer createSockJSServer(HttpServer httpServer); /** * The File system object */ FileSystem fileSystem(); /** * The event bus */ EventBus eventBus(); /** * Return the {@link DnsClient} */ DnsClient createDnsClient(InetSocketAddress... dnsServers); /** * The shared data object */ SharedData sharedData(); /** * Set a one-shot timer to fire after {@code delay} milliseconds, at which point {@code handler} will be called with * the id of the timer. * * @return the unique ID of the timer */ long setTimer(long delay, Handler handler); /** * Set a periodic timer to fire every {@code delay} milliseconds, at which point {@code handler} will be called with * the id of the timer. * * @return the unique ID of the timer */ long setPeriodic(long delay, Handler handler); /** * Cancel the timer with the specified {@code id}. Returns {@code} true if the timer was successfully cancelled, or * {@code false} if the timer does not exist. */ boolean cancelTimer(long id); /** * @return The current context */ Context currentContext(); /** * Put the handler on the event queue for the current loop (or worker context) so it will be run asynchronously ASAP after this event has * been processed */ void runOnContext(Handler action); /** * This allows you to exe */ void executeBlocking(Action action, Handler> resultHandler); /** * Is the current thread an event loop thread? * * @return true if current thread is an event loop thread */ boolean isEventLoop(); /** * Is the current thread an worker thread? * * @return true if current thread is an worker thread */ boolean isWorker(); /** * Is the current instance clustered? * * @return true if the current instance is clustered */ boolean isClustered(); /** * This method returns the Manager only if the instance is clustered. * * @return The ClusterManager associated with the clustered Async instance */ ClusterManager clusterManager(); /** * Stop the eventbus and any resource managed by the eventbus. */ void stop(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy