org.productivity.java.syslog4j.server.SyslogServerIF Java Examples
The following examples show how to use
org.productivity.java.syslog4j.server.SyslogServerIF.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public static void handleSessionOpen(Sessions sessions, SyslogServerIF syslogServer, Socket socket) { List eventHandlers = syslogServer.getConfig().getEventHandlers(); for(int i=0; i<eventHandlers.size(); i++) { SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i); if (eventHandler instanceof SyslogServerSessionEventHandlerIF) { try { Object session = ((SyslogServerSessionEventHandlerIF) eventHandler).sessionOpened(syslogServer,socket.getRemoteSocketAddress()); if (session != null) { sessions.addSession(socket,eventHandler,session); } } catch (Exception exception) { try { ((SyslogServerSessionEventHandlerIF) eventHandler).exception(null,syslogServer,socket.getRemoteSocketAddress(),exception); } catch (Exception e) { // } } } } }
Example #2
Source File: AbstractSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public static void handleSessionClosed(Sessions sessions, SyslogServerIF syslogServer, Socket socket, boolean timeout) { List eventHandlers = syslogServer.getConfig().getEventHandlers(); for(int i=0; i<eventHandlers.size(); i++) { SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i); if (eventHandler instanceof SyslogServerSessionEventHandlerIF) { Object session = sessions.getSession(socket,eventHandler); try { ((SyslogServerSessionEventHandlerIF) eventHandler).sessionClosed(session,syslogServer,socket.getRemoteSocketAddress(),timeout); } catch (Exception exception) { try { ((SyslogServerSessionEventHandlerIF) eventHandler).exception(session,syslogServer,socket.getRemoteSocketAddress(),exception); } catch (Exception e) { // } } } } }
Example #3
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testFreshConnectionInterval() { TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(); serverConfig.setPort(8888); SocketCounter counter = new SocketCounter(); serverConfig.addEventHandler(counter); SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_8888",serverConfig); SyslogUtility.sleep(100); TCPNetSyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(8888); config.setFreshConnectionInterval(300); SyslogIF syslog = Syslog.createInstance("tcp_8888",config); for(int i=0; i<10; i++) { syslog.info("message " + i); SyslogUtility.sleep(100); } SyslogUtility.sleep(100); SyslogServer.destroyInstance(server); Syslog.destroyInstance(syslog); SyslogUtility.sleep(100); assertEquals("OpenCounter",3,counter.openCounter); assertEquals("EventCounter",10,counter.eventCounter); assertEquals("CloseCounter",3,counter.closeCounter); }
Example #4
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { if (session != null) { okay = false; } System.out.println("closed: " + id); }
Example #5
Source File: SyslogCreateAndDestroyTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testCreateAndDestroyServerByProtocol() { UDPNetSyslogServerConfig config = new UDPNetSyslogServerConfig(); config.setPort(999); SyslogServerIF server = SyslogServer.createInstance("udpToDestroy",config); SyslogServerIF matchServer = SyslogServer.getInstance("udpToDestroy"); assertEquals(server,matchServer); SyslogServer.destroyInstance(""); SyslogServer.destroyInstance("udpToDestroy"); try { SyslogServer.getInstance("udpToDestroy"); fail("udpToDestroy should not exist"); } catch (SyslogRuntimeException sre) { // } assertFalse(SyslogServer.getSuppressRuntimeExceptions()); SyslogServer.setSuppressRuntimeExceptions(true); assertTrue(SyslogServer.getSuppressRuntimeExceptions()); assertNull(SyslogServer.getInstance("udpToDestroy")); SyslogServer.setSuppressRuntimeExceptions(false); }
Example #6
Source File: TCPNetSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public TCPNetSyslogSocketHandler(Sessions sessions, SyslogServerIF server, Socket socket) { this.sessions = sessions; this.server = server; this.socket = socket; synchronized(this.sessions) { this.sessions.addSocket(socket); } }
Example #7
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { if (session != null) { int i = translate((String) session); if (i != -1) { closeCount[i]++; } } System.out.println("closed: " + id + "/" + session.toString()); }
Example #8
Source File: TCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { if (timeout) { System.out.println("Timeout after event: " + lastEvent.getMessage()); assertTrue(lastEvent.getMessage().endsWith("yes")); } else { assertTrue(lastEvent.getMessage().endsWith("no")); } System.out.println("Closed"); }
Example #9
Source File: AbstractSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public static void handleDestroy(SyslogServerIF syslogServer) { List eventHandlers = syslogServer.getConfig().getEventHandlers(); for(int i=0; i<eventHandlers.size(); i++) { SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i); try { eventHandler.destroy(syslogServer); } catch (Exception exception) { // } } }
Example #10
Source File: AbstractSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public static void handleInitialize(SyslogServerIF syslogServer) { List eventHandlers = syslogServer.getConfig().getEventHandlers(); for(int i=0; i<eventHandlers.size(); i++) { SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i); try { eventHandler.initialize(syslogServer); } catch (Exception exception) { // } } }
Example #11
Source File: TCPSyslogSocketHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Constructor. * * @param sockets Set of all registered handlers. * @param server Syslog server instance * @param socket socket returned from the serverSocket.accept() */ public TCPSyslogSocketHandler(Set<Socket> sockets, SyslogServerIF server, Socket socket) { this.sockets = sockets; this.server = server; this.socket = socket; synchronized (this.sockets) { this.sockets.add(this.socket); } }
Example #12
Source File: AbstractSyslogReconnectionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static SyslogServerIF createAndStartSyslogInstance(SyslogServerConfigIF config, String host, int port, String protocol) { config.setUseStructuredData(true); config.setHost(host); config.setPort(port); config.addEventHandler(new BlockedAllProtocolsSyslogServerEventHandler(protocol)); SyslogServerIF syslogServer = SyslogServer.createInstance(protocol, config); SyslogServer.getThreadedInstance(protocol); return syslogServer; }
Example #13
Source File: TCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) { System.out.println("Open"); return null; }
Example #14
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(SyslogServerIF syslogServer) { this.initialized = true; System.out.println("initialized " + syslogServer.getProtocol()); }
Example #15
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void destroy(SyslogServerIF syslogServer) { this.destroyed = true; System.out.println("destroyed " + syslogServer.getProtocol()); }
Example #16
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(SyslogServerIF syslogServer) { this.initialized = true; System.out.println("initialized " + syslogServer.getProtocol()); }
Example #17
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { // }
Example #18
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) { okay = false; return null; }
Example #19
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void destroy(SyslogServerIF syslogServer) { this.destroyed = true; System.out.println("destroyed " + syslogServer.getProtocol()); }
Example #20
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testTCPSession() { SyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(9999); TCPSessionHandler handler1 = new TCPSessionHandler("a"); serverConfig.addEventHandler(handler1); TCPSessionHandler handler2 = new TCPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(9999); TCPNetSyslogServer tcpServer = (TCPNetSyslogServer) server; SyslogIF syslog1 = Syslog.createInstance("tcp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogUtility.sleep(100); assertEquals(1,tcpServer.getSessions().size()); SyslogIF syslog2 = Syslog.createInstance("tcp_session_2",config); syslog2.info("3"); syslog2.info("4"); syslog1.info("5"); syslog1.info("6"); syslog2.info("7"); syslog2.info("8"); SyslogUtility.sleep(100); assertEquals(2,tcpServer.getSessions().size()); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("tcp_session"); try { SyslogServer.getInstance("tcp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertEquals(4,handler1.eventCount[0]); assertEquals(0,handler1.eventCount[1]); assertEquals(4,handler1.eventCount[2]); assertEquals(0,handler1.eventCount[3]); assertEquals(0,handler2.eventCount[0]); assertEquals(4,handler2.eventCount[1]); assertEquals(0,handler2.eventCount[2]); assertEquals(4,handler2.eventCount[3]); assertEquals(1,handler1.closeCount[0]); assertEquals(0,handler1.closeCount[1]); assertEquals(1,handler1.closeCount[2]); assertEquals(0,handler1.closeCount[3]); assertEquals(0,handler2.closeCount[0]); assertEquals(1,handler2.closeCount[1]); assertEquals(0,handler2.closeCount[2]); assertEquals(1,handler2.closeCount[3]); SyslogUtility.sleep(100); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }
Example #21
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(SyslogServerIF syslogServer) { // }
Example #22
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) { openCounter++; return null; }
Example #23
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { closeCounter++; }
Example #24
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void destroy(SyslogServerIF syslogServer) { // }
Example #25
Source File: CommandLineNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) { return null; }
Example #26
Source File: CommandLineNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) { // }
Example #27
Source File: PrintStreamSyslogServerEventHandler.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void destroy(SyslogServerIF syslogServer) { return; }
Example #28
Source File: TCPSyslogServerConfig.java From simple-syslog-server with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Class<? extends SyslogServerIF> getSyslogServerClass() { return TCPSyslogServer.class; }
Example #29
Source File: UDPSyslogServerConfig.java From simple-syslog-server with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Class<? extends SyslogServerIF> getSyslogServerClass() { return UDPSyslogServer.class; }
Example #30
Source File: AbstractSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, DatagramPacket packet, SyslogServerEventIF event) { handleEvent(sessions,syslogServer,null,packet.getSocketAddress(),event); }