001: /*_############################################################################
002: _##
003: _## SNMP4J - SNMP4JSettings.java
004: _##
005: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j;
022:
023: import org.snmp4j.util.ThreadFactory;
024: import org.snmp4j.util.DefaultThreadFactory;
025: import org.snmp4j.util.TimerFactory;
026: import org.snmp4j.util.DefaultTimerFactory;
027:
028: /**
029: * The <code>SNMP4JSettings</code> class implements a central configuration
030: * class of the SNMP4J framework. As a rule of thumb, changes to the default
031: * configuration should be made before any other classes of the SNMP4J API are
032: * instantiated or referenced by the application code.
033: *
034: * @author Frank Fock
035: * @version 1.9
036: * @since 1.5
037: */
038: public final class SNMP4JSettings {
039:
040: /**
041: * Specifies whether SNMP4J can be extended by own implementation of
042: * security protocols, transport mappings, address types, SMI syntaxes, etc.
043: * through property files defined via System properties.
044: * If set to <code>false</code> all classes SNMP4J is aware of will be
045: * used hard coded which speeds up initialization and is required to use
046: * SNMP4J in a secure environment where System properties are not available
047: * (i.e. in an unsigned applet).
048: * @since 1.2.2
049: */
050: private static boolean extensibilityEnabled = false;
051:
052: /**
053: * By default SNMP4J (and SNMP4J-Agent*) catch runtime exceptions at thread
054: * boundaries of API controlled threads. In SNMP4J such a thread runs in each
055: * {@link TransportMapping} and in each {@link Snmp} session object. To ensure
056: * robust runtime behavior, unexpected runtime exceptions are caught and
057: * logged. If you need to localize and debug such exceptions then set this
058: * value to <code>true</code>.
059: *
060: * @since 1.8.1
061: */
062: private static volatile boolean forwardRuntimeExceptions = false;
063:
064: /**
065: * By default SNMP4J uses {@link java.util.Thread} instances to run
066: * concurrent tasks. For environments with restricted thread management
067: * like Java EE application servers, a custom thread factory can be used.
068: *
069: * @since 1.9
070: */
071: private static ThreadFactory threadFactory = new DefaultThreadFactory();
072:
073: /**
074: * By default SNMP4J uses {@link java.util.Timer} instances to run
075: * timed tasks. For environments with restricted thread management
076: * like Java EE application servers, a custom timer factory can be used.
077: *
078: * @since 1.9
079: */
080: private static TimerFactory timerFactory = new DefaultTimerFactory();
081:
082: /**
083: * Enables (or disables) the extensibility feature of SNMP4J. When enabled,
084: * SNMP4J checks certain properties files that describe which transport
085: * mappings, address types, SMI syntaxes, security protocols, etc. should be
086: * supported by SNMP4J.
087: * <p>
088: * By default, the extensibility feature is disabled which provides a faster
089: * startup and since no system properties are read, it ensures that SNMP4J
090: * can be used also in secure environments like applets.
091: * @param enable
092: * if <code>true</code> activates extensibility or if <code>false</code>
093: * disables it. In the latter case, SNMP4J's default configuration will
094: * be used with all available features.
095: * @since 1.2.2
096: */
097: public static void setExtensibilityEnabled(boolean enable) {
098: extensibilityEnabled = enable;
099: }
100:
101: /**
102: * Tests if the extensibility feature is enabled.
103: * @return
104: * if <code>true</code> the extensibility is enabled otherwise it is
105: * disabled. In the latter case, SNMP4J's default configuration will
106: * be used with all available features.
107: * @since 1.2.2
108: */
109: public final static boolean isExtensibilityEnabled() {
110: return extensibilityEnabled;
111: }
112:
113: /**
114: * Enables or disables runtime exception forwarding.
115: * @see #forwardRuntimeExceptions
116: * @param forwardExceptions
117: * <code>true</code> runtime exceptions are thrown on thread boundaries
118: * controlled by SNMP4J and related APIs. Default is <code>false</code>.
119: * @since 1.8.1
120: */
121: public static void setForwardRuntimeExceptions(
122: boolean forwardExceptions) {
123: forwardRuntimeExceptions = forwardExceptions;
124: }
125:
126: /**
127: * Indicates whether runtime exceptions should be thrown on thread boundaries
128: * controlled by SNMP4J and related APIs.
129: * @return
130: * <code>true</code> runtime exceptions are thrown on thread boundaries
131: * controlled by SNMP4J and related APIs. Default is <code>false</code>.
132: * @since 1.8.1
133: */
134: public final static boolean isFowardRuntimeExceptions() {
135: return forwardRuntimeExceptions;
136: }
137:
138: /**
139: * Gets the thread factory.
140: * @return
141: * a ThreadFactory.
142: * @since 1.9
143: */
144: public final static ThreadFactory getThreadFactory() {
145: return threadFactory;
146: }
147:
148: /**
149: * Sets the thread factory for creating new threads of execution.
150: * @param newThreadFactory
151: * a ThreadFactory (must not be <code>null</code>).
152: * @since 1.9
153: */
154: public final static void setThreadFactory(
155: ThreadFactory newThreadFactory) {
156: if (newThreadFactory == null) {
157: throw new NullPointerException();
158: }
159: threadFactory = newThreadFactory;
160: }
161:
162: /**
163: * Gets the timer factory.
164: * @return
165: * a TimerFactory.
166: * @since 1.9
167: */
168: public final static TimerFactory getTimerFactory() {
169: return timerFactory;
170: }
171:
172: /**
173: * Sets the timer factory for creating new timer instances.
174: * @param newTimerFactory
175: * a TimerFactory (must not be <code>null</code>).
176: * @since 1.9
177: */
178: public final static void setTimerFactory(
179: TimerFactory newTimerFactory) {
180: if (newTimerFactory == null) {
181: throw new NullPointerException();
182: }
183: timerFactory = newTimerFactory;
184: }
185:
186: }
|