Java Code Examples for org.productivity.java.syslog4j.server.SyslogServer#getInstance()
The following examples show how to use
org.productivity.java.syslog4j.server.SyslogServer#getInstance() .
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: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected void startServerThread(String protocol) { assertTrue(SyslogServer.exists(protocol)); this.server = SyslogServer.getInstance(protocol); if (isSyslogServerTcpBacklog() && this.server.getConfig() instanceof TCPNetSyslogServerConfig) { ((TCPNetSyslogServerConfig) this.server.getConfig()).setBacklog(0); } AbstractNetSyslogServerConfig config = (AbstractNetSyslogServerConfig) this.server.getConfig(); config.setPort(TEST_PORT); config.addEventHandler(this.recorderEventHandler); if (this.server.getThread() == null) { Thread t = new Thread(this.server); t.setName("SyslogServer: " + protocol); t.start(); this.server.setThread(t); assertEquals(t,this.server.getThread()); } }
Example 2
Source File: AbstractLog4jSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
protected void startServerThread(String protocol) { this.server = SyslogServer.getInstance(protocol); AbstractNetSyslogServerConfig config = (AbstractNetSyslogServerConfig) this.server.getConfig(); config.setPort(TEST_PORT); config.addEventHandler(this.recorderEventHandler); this.server = SyslogServer.getThreadedInstance(protocol); }
Example 3
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 4
Source File: NonDefinedSyslogInstanceTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testNonDefinedSyslogServerInstance() { try { SyslogServer.getInstance("not_defined"); fail("not_defined shouldn't exist"); } catch (SyslogRuntimeException sre) { assertTrue(sre.getMessage().startsWith("SyslogServer instance \"not_defined\" not defined; use \"tcp\" or \"udp\" or call SyslogServer.createInstance(protocol,config) first")); } }
Example 5
Source File: PrintStreamServerEventTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testPrintStreamEvent() { SyslogServerIF server = SyslogServer.getInstance("udp"); String message = "test message"; InetAddress inetAddress = null; try { inetAddress = InetAddress.getLocalHost(); } catch (UnknownHostException uhe) { } SyslogServerEventIF event = new SyslogServerEvent(message.getBytes(),message.length(),inetAddress); assertEquals(SyslogConstants.CHAR_SET_DEFAULT,event.getCharSet()); event.setCharSet("xxyyzz"); assertEquals("xxyyzz",event.getCharSet()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); SyslogServerSessionEventHandlerIF eventHandler = new PrintStreamSyslogServerEventHandler(ps); eventHandler.sessionOpened(server,null); eventHandler.event(null,server,null,event); eventHandler.exception(null,server,null,null); eventHandler.sessionClosed(null,server,null,false); assertEquals(event.getMessage(),new String("test message")); Date date = new Date(); event.setDate(date); assertTrue(date == event.getDate()); event.setFacility(SyslogConstants.FACILITY_LOCAL0); assertEquals(SyslogConstants.FACILITY_LOCAL0,event.getFacility()); event.setHost("foo"); assertEquals("foo",event.getHost()); event.setLevel(SyslogConstants.LEVEL_DEBUG); assertEquals(SyslogConstants.LEVEL_DEBUG,event.getLevel()); event.setMessage(message); assertEquals(message,event.getMessage()); eventHandler = SystemOutSyslogServerEventHandler.create(); eventHandler.event(null,server,null,event); eventHandler = new SystemErrSyslogServerEventHandler(); eventHandler.event(null,server,null,event); try { File f = File.createTempFile("syslog4j-test",".txt"); eventHandler = new FileSyslogServerEventHandler(f.getPath()); eventHandler.event(null,server,null,event); eventHandler = new FileSyslogServerEventHandler(f.getPath(),true); eventHandler.event(null,server,null,event); } catch (Exception e) { fail(e.toString()); } }
Example 6
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 7
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void testUDPSession() { SyslogServerConfigIF serverConfig = new UDPNetSyslogServerConfig(9999); UDPSessionHandler handler1 = new UDPSessionHandler("a"); serverConfig.addEventHandler(handler1); UDPSessionHandler handler2 = new UDPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServer.createThreadedInstance("udp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new UDPNetSyslogConfig(); config.setPort(9999); SyslogIF syslog1 = Syslog.createInstance("udp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogIF syslog2 = Syslog.createInstance("udp_session_2",config); syslog2.info("3"); syslog2.info("4"); SyslogUtility.sleep(100); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("udp_session"); try { SyslogServer.getInstance("udp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertTrue(handler1.okay); assertTrue(handler2.okay); SyslogUtility.sleep(250); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }