package org.glassfish.grizzly.nio;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.grizzly.Grizzly;
class SelectionKeyHandlerInitializer {
private static final String PROP = "org.glassfish.grizzly.DEFAULT_SELECTION_KEY_HANDLER";
private static final Logger LOGGER = Grizzly.logger(SelectionKeyHandlerInitializer.class);
@SuppressWarnings("unchecked")
static SelectionKeyHandler initHandler() {
final String className = System.getProperty(PROP);
if (className != null) {
try {
Class<? extends SelectionKeyHandler> handlerClass = (Class<? extends SelectionKeyHandler>) Class.forName(className, true,
SelectionKeyHandler.class.getClassLoader());
return handlerClass.newInstance();
} catch (Exception e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, "Unable to load or create a new instance of SelectionKeyHandler {0}. Cause: {1}",
new Object[] { className, e.getMessage() });
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, e.toString(), e);
}
return new DefaultSelectionKeyHandler();
}
}
return new DefaultSelectionKeyHandler();
}
}