org.productivity.java.syslog4j.SyslogRuntimeException Java Examples
The following examples show how to use
org.productivity.java.syslog4j.SyslogRuntimeException.
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: MacSyslogMessageModifier.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public MacSyslogMessageModifier(MacSyslogMessageModifierConfig config) throws SyslogRuntimeException { super(config); this.config = config; try { this.mac = Mac.getInstance(config.getMacAlgorithm()); this.mac.init(config.getKey()); } catch (NoSuchAlgorithmException nsae) { throw new SyslogRuntimeException(nsae); } catch (InvalidKeyException ike) { throw new SyslogRuntimeException(ike); } }
Example #2
Source File: TCPNetSyslogWriter.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected void closeSocket(Socket socketToClose) { if (socketToClose == null) { return; } try { socketToClose.close(); } catch (IOException ioe) { if (!"Socket is closed".equalsIgnoreCase(ioe.getMessage())) { throw new SyslogRuntimeException(ioe); } } finally { if (socketToClose == this.socket) { this.socket = null; } } }
Example #3
Source File: TCPNetSyslogServer.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void initialize() throws SyslogRuntimeException { this.tcpNetSyslogServerConfig = null; try { this.tcpNetSyslogServerConfig = (TCPNetSyslogServerConfigIF) this.syslogServerConfig; } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must be of type TCPNetSyslogServerConfig"); } if (this.syslogServerConfig == null) { throw new SyslogRuntimeException("config cannot be null"); } if (this.tcpNetSyslogServerConfig.getBacklog() < 1) { this.tcpNetSyslogServerConfig.setBacklog(SyslogConstants.SERVER_SOCKET_BACKLOG_DEFAULT); } }
Example #4
Source File: GenericSyslogPoolFactory.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException { SyslogPoolConfigIF poolConfig = null; try { poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig(); } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF"); } genericObjectPool.setMaxActive(poolConfig.getMaxActive()); genericObjectPool.setMaxIdle(poolConfig.getMaxIdle()); genericObjectPool.setMaxWait(poolConfig.getMaxWait()); genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis()); genericObjectPool.setMinIdle(poolConfig.getMinIdle()); genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun()); genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis()); genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow()); genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn()); genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle()); genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis()); genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction()); }
Example #5
Source File: SyslogParameterTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testMessageModifier(AbstractSyslogConfigIF syslogConfig) { syslogConfig.removeAllMessageModifiers(); syslogConfig.addMessageModifier(null); syslogConfig.insertMessageModifier(0,null); try { syslogConfig.insertMessageModifier(888, StringCaseSyslogMessageModifier.LOWER); fail("should generate IndexOutOfBoundsException"); } catch (SyslogRuntimeException sre) { // } syslogConfig.removeMessageModifier(null); }
Example #6
Source File: UDPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected synchronized void createDatagramSocket(boolean initialize) { try { this.socket = new DatagramSocket(); } catch (SocketException se) { if (initialize) { if (this.syslogConfig.isThrowExceptionOnInitialize()) { throw new SyslogRuntimeException(se); } } else { throw new SyslogRuntimeException(se); } } if (this.socket == null) { throw new SyslogRuntimeException("Cannot seem to get a Datagram socket"); } }
Example #7
Source File: HashSyslogMessageModifier.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public HashSyslogMessageModifier(HashSyslogMessageModifierConfig config) throws SyslogRuntimeException { super(config); this.config = config; if (this.config == null) { throw new SyslogRuntimeException("Hash config object cannot be null"); } if (this.config.getHashAlgorithm() == null) { throw new SyslogRuntimeException("Hash algorithm cannot be null"); } try { MessageDigest.getInstance(config.getHashAlgorithm()); } catch (NoSuchAlgorithmException nsae){ throw new SyslogRuntimeException(nsae); } }
Example #8
Source File: SyslogCreateAndDestroyTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testCreateAndDestroyByProtocol() { UDPNetSyslogConfig config = new UDPNetSyslogConfig(); config.setPort(999); SyslogIF syslog = Syslog.createInstance("udpToDestroy",config); assertEquals(SyslogMessageProcessor.getDefault(),syslog.getMessageProcessor()); SyslogMessageProcessorIF messageProcessor = new FakeMessageProcessor(); syslog.setMessageProcessor(messageProcessor); assertEquals(messageProcessor,syslog.getMessageProcessor()); SyslogIF matchSyslog = Syslog.getInstance("udpToDestroy"); assertEquals(syslog,matchSyslog); Syslog.destroyInstance(""); Syslog.destroyInstance("udpToDestroy"); try { Syslog.getInstance("udpToDestroy"); fail("udpToDestroy should not exist"); } catch (SyslogRuntimeException sre) { // } }
Example #9
Source File: AbstractSyslogConfig.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier) { if (messageModifier == null) { return; } List _messageModifiers = _getMessageModifiers(); synchronized(_messageModifiers) { try { _messageModifiers.add(index,messageModifier); } catch (IndexOutOfBoundsException ioobe) { throw new SyslogRuntimeException(ioobe); } } }
Example #10
Source File: AbstractSyslogConfig.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler) { if (backLogHandler == null) { return; } List _backLogHandlers = _getBackLogHandlers(); synchronized(_backLogHandlers) { try { backLogHandler.initialize(); _backLogHandlers.add(index,backLogHandler); } catch (IndexOutOfBoundsException ioobe) { throw new SyslogRuntimeException(ioobe); } } }
Example #11
Source File: TCPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected void write(int level, byte[] message) throws SyslogRuntimeException { AbstractSyslogWriter syslogWriter = getWriter(); try { if (syslogWriter.hasThread()) { syslogWriter.queue(level,message); } else { synchronized(syslogWriter) { syslogWriter.write(message); } } } finally { returnWriter(syslogWriter); } }
Example #12
Source File: UDPSyslogServer.java From simple-syslog-server with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void run() { this.shutdown = false; try { this.ds = createDatagramSocket(); } catch (Exception e) { System.err.println("Creating DatagramSocket failed"); e.printStackTrace(); throw new SyslogRuntimeException(e); } byte[] receiveData = new byte[SyslogConstants.SYSLOG_BUFFER_SIZE]; while (!this.shutdown) { try { final DatagramPacket dp = new DatagramPacket(receiveData, receiveData.length); this.ds.receive(dp); final SyslogServerEventIF event = new Rfc5424SyslogEvent(receiveData, dp.getOffset(), dp.getLength()); System.out.println(">>> Syslog message came: " + event); } catch (SocketException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Example #13
Source File: MacSyslogMessageModifierConfig.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, String base64Key) { this.macAlgorithm = macAlgorithm; this.keyAlgorithm = keyAlgorithm; byte[] keyBytes = Base64.decode(base64Key); try { this.key = new SecretKeySpec(keyBytes,keyAlgorithm); } catch (IllegalArgumentException iae) { throw new SyslogRuntimeException(iae); } }
Example #14
Source File: UnixSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void initialize() throws SyslogRuntimeException { try { this.unixSyslogConfig = (UnixSyslogConfig) this.syslogConfig; } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must be of type UnixSyslogConfig"); } loadLibrary(this.unixSyslogConfig); }
Example #15
Source File: AbstractSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
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 #16
Source File: UnixSocketSyslogConfig.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void setFamily(String family) { if (family == null) { throw new SyslogRuntimeException("Family cannot be null for class \"" + this.getClass().getName() + "\""); } if ("AF_UNIX".equalsIgnoreCase(family.trim())) { this.family = AF_UNIX; } else { throw new SyslogRuntimeException("Family must be \"AF_UNIX\" for class \"" + this.getClass().getName() + "\""); } }
Example #17
Source File: TCPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void initialize() throws SyslogRuntimeException { super.initialize(); try { this.tcpNetSyslogConfig = (TCPNetSyslogConfigIF) this.syslogConfig; } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface TCPNetSyslogConfigIF"); } }
Example #18
Source File: Log4jSyslogBackLogHandler.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public Log4jSyslogBackLogHandler(Class loggerClass, boolean appendReason) { if (loggerClass == null) { throw new SyslogRuntimeException("loggerClass cannot be null"); } this.logger = Logger.getLogger(loggerClass); this.appendReason = appendReason; initialize(); }
Example #19
Source File: TCPNetSyslogWriter.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public synchronized void shutdown() throws SyslogRuntimeException { this.shutdown = true; if (this.syslogConfig.isThreaded()) { long timeStart = System.currentTimeMillis(); boolean done = false; while(!done) { if (this.socket == null || this.socket.isClosed()) { done = true; } else { long now = System.currentTimeMillis(); if (now > (timeStart + this.tcpNetSyslogConfig.getMaxShutdownWait())) { closeSocket(this.socket); this.thread.interrupt(); done = true; } if (!done) { SyslogUtility.sleep(SyslogConstants.SHUTDOWN_INTERVAL); } } } } else { if (this.socket == null || this.socket.isClosed()) { return; } closeSocket(this.socket); } }
Example #20
Source File: Log4jSyslogBackLogHandler.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public Log4jSyslogBackLogHandler(Class loggerClass) { if (loggerClass == null) { throw new SyslogRuntimeException("loggerClass cannot be null"); } this.logger = Logger.getLogger(loggerClass); initialize(); }
Example #21
Source File: Log4jSyslogBackLogHandler.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public Log4jSyslogBackLogHandler(String loggerName) { if (loggerName == null) { throw new SyslogRuntimeException("loggerName cannot be null"); } this.logger = Logger.getLogger(loggerName); initialize(); }
Example #22
Source File: Log4jSyslogBackLogHandler.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public Log4jSyslogBackLogHandler(String loggerName, boolean appendReason) { if (loggerName == null) { throw new SyslogRuntimeException("loggerName cannot be null"); } this.logger = Logger.getLogger(loggerName); this.appendReason = appendReason; initialize(); }
Example #23
Source File: AbstractSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void log(SyslogMessageProcessorIF messageProcessor, int level, String message) { String _message = null; if (this.syslogConfig.isIncludeIdentInMessageModifier()) { _message = prefixMessage(message,IDENT_SUFFIX_DEFAULT); _message = modifyMessage(level,_message); } else { _message = modifyMessage(level,message); _message = prefixMessage(_message,IDENT_SUFFIX_DEFAULT); } try { write(messageProcessor, level,_message); } catch (SyslogRuntimeException sre) { if (sre.getCause() != null) { backLog(level,_message,sre.getCause()); } else { backLog(level,_message,sre); } if (this.syslogConfig.isThrowExceptionOnWrite()) { throw sre; } } }
Example #24
Source File: TCPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void flush() throws SyslogRuntimeException { AbstractSyslogWriter syslogWriter = getWriter(false); if (syslogWriter != null) { syslogWriter.flush(); } }
Example #25
Source File: MultipleSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void shutdown() throws SyslogRuntimeException { for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) { String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i); SyslogIF syslog = Syslog.getInstance(protocol); syslog.shutdown(); } }
Example #26
Source File: PooledTCPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void flush() throws SyslogRuntimeException { try { this.poolFactory.clear(); } catch (Exception e) { // } }
Example #27
Source File: PooledTCPNetSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void returnWriter(AbstractSyslogWriter syslogWriter) { try { this.poolFactory.returnSyslogWriter(syslogWriter); } catch (Exception e) { throw new SyslogRuntimeException(e); } }
Example #28
Source File: NonDefinedSyslogInstanceTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testNonDefinedSyslogInstance() { try { Syslog.getInstance("not_defined"); fail("not_defined shouldn't exist"); } catch (SyslogRuntimeException sre) { assertTrue(sre.getMessage().startsWith("Syslog protocol \"not_defined\" not defined; call Syslogger.createSyslogInstance(protocol,config) first or use one of the following instances: ")); } }
Example #29
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 #30
Source File: AbstractSyslogWriter.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void initialize(AbstractSyslog abstractSyslog) { this.syslog = abstractSyslog; try { this.syslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig(); } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface AbstractSyslogConfigIF"); } if (this.syslogConfig.isThreaded()) { this.queuedMessages = new LinkedList(); } }