001/* 002 * Copyright 2012-2014 Donghwan Kim 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.github.flowersinthesand.portal; 017 018import io.github.flowersinthesand.wes.Action; 019import io.github.flowersinthesand.wes.ServerHttpExchange; 020import io.github.flowersinthesand.wes.ServerWebSocket; 021 022/** 023 * Server for Portal. 024 * <p> 025 * Server is a server-side wes application which provides and manages 026 * {@link Socket} processing HTTP request and WebSocket so that it can run on 027 * any framework wes supports. See <a 028 * href="http://flowersinthesand.github.io/wes" target="_parent">wes</a> 029 * documentation for how to install and what frameworks are supported. 030 * <p> 031 * If you are using dependency injection framework like Spring, you can create 032 * Server as component of singleton scope and inject it where you need to 033 * communicate with client in real time. 034 * <p> 035 * Server may be accessed by multiple threads. 036 * 037 * @author Donghwan Kim 038 */ 039public interface Server { 040 041 /** 042 * Executes the given action retrieving all of the socket in this server. 043 */ 044 Server all(Action<Socket> action); 045 046 /** 047 * Executes the given action retrieving the socket of the given id. The 048 * given action will be executed only once if socket is found and won't be 049 * executed if not found. 050 */ 051 Server byId(String id, Action<Socket> action); 052 053 /** 054 * Executes the given action retrieving the socket tagged with the given 055 * name. The given action will be executed multiple times if sockets are 056 * found and won't be executed if not found. 057 */ 058 Server byTag(String name, Action<Socket> action); 059 060 /** 061 * Executes the given action retrieving the socket tagged with all of the 062 * given names. The given action will be executed multiple times if sockets 063 * are found and won't be executed if not found. 064 */ 065 Server byTag(String[] names, Action<Socket> action); 066 067 /** 068 * Registers an action to be called when the socket has been opened. It's 069 * allowed to add several actions before and after installation, so you 070 * don't need to centralize all your code to one class. 071 */ 072 Server socketAction(Action<Socket> action); 073 074 /** 075 * ServerHttpExchange action to install in wes 076 */ 077 Action<ServerHttpExchange> httpAction(); 078 079 /** 080 * ServerWebSocket action to install in wes 081 */ 082 Action<ServerWebSocket> websocketAction(); 083 084}