org.productivity.java.syslog4j.SyslogConfigIF Java Examples

The following examples show how to use org.productivity.java.syslog4j.SyslogConfigIF. 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: SyslogParameterTest.java    From syslog4j with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testStructuredSyslogMessage() {
	SyslogConfigIF config = new UDPNetSyslogConfig();
	config.setUseStructuredData(true);
	assertTrue(config.isUseStructuredData());
	config.setUseStructuredData(false);
	assertFalse(config.isUseStructuredData());
	
	SyslogIF syslog = Syslog.createInstance("testStructuredSyslog",config);
	
	SyslogMessageProcessorIF messageProcessor = new StructuredSyslogMessageProcessor();
	syslog.setStructuredMessageProcessor(messageProcessor);
	assertEquals(messageProcessor,syslog.getStructuredMessageProcessor());
	
	SyslogMessageIF m1 = new StructuredSyslogMessage("test1",new HashMap(),"test2");
	SyslogMessageIF m2 = new StructuredSyslogMessage("test1",new HashMap(),"test2");
	SyslogMessageIF m3 = new StructuredSyslogMessage("test3",new HashMap(),"test2");
	SyslogMessageIF m4 = new StructuredSyslogMessage("test1",new HashMap(),"test4");
	
	assertFalse(m1.equals(null));
	assertFalse(m1.equals("Wrong Class"));
	assertTrue(m1.equals(m1));
	assertTrue(m2.equals(m2));
	
	assertFalse(m1.equals(m3));
	assertFalse(m1.equals(m4));
}
 
Example #2
Source File: MultipleSyslog.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
	this.syslogProtocol = protocol;
	
	try {
		this.multipleSyslogConfig = (MultipleSyslogConfig) config;
		
	} catch (ClassCastException cce) {
		throw new SyslogRuntimeException("config must be of type MultipleSyslogConfig");
	}
}
 
Example #3
Source File: AbstractSyslog.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
	this.syslogProtocol = protocol;

	try {
		this.syslogConfig = (AbstractSyslogConfigIF) config;
		
	} catch (ClassCastException cce) {
		throw new SyslogRuntimeException("provided config must implement AbstractSyslogConfigIF");
	}
	
	initialize();
}
 
Example #4
Source File: SplitSyslogTest.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void setMessageLength(int length) {
	SyslogConfigIF config = Syslog.getInstance("split").getConfig();
	
	String localName = SyslogUtility.getLocalName();
	this.localNameLength = localName.length();
	
	config.setMaxMessageLength(21 + this.localNameLength + length);
}
 
Example #5
Source File: MultipleSyslog.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SyslogConfigIF getConfig() {
	return this.multipleSyslogConfig;
}
 
Example #6
Source File: AbstractSyslog.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SyslogConfigIF getConfig() {
	return this.syslogConfig;
}
 
Example #7
Source File: MultipleSyslogCreateTest.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void initialize(String syslogProtocol, SyslogConfigIF syslogConfig) throws SyslogRuntimeException {
	this.protocol = syslogProtocol;
	this.config = syslogConfig;
}
 
Example #8
Source File: SyslogServerSessionTest.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
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 #9
Source File: Syslog4jAppender.java    From logback-syslog4j with MIT License 4 votes vote down vote up
public SyslogConfigIF getSyslogConfig() {
    return syslogConfig;
}
 
Example #10
Source File: Syslog4jAppender.java    From logback-syslog4j with MIT License 4 votes vote down vote up
public void setSyslogConfig(SyslogConfigIF syslogConfig) {
    this.syslogConfig = syslogConfig;
}
 
Example #11
Source File: SyslogServerSessionTest.java    From syslog4j with GNU Lesser General Public License v2.1 2 votes vote down vote up
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);
}
 
Example #12
Source File: MultipleSyslogCreateTest.java    From syslog4j with GNU Lesser General Public License v2.1 votes vote down vote up
public SyslogConfigIF getConfig() { return this.config; }