Fields Summary |
---|
public static final String | PROTOCOL_FINDERS |
public static final String | PROTOCOL_HANDLERS |
private ConcurrentHashMap | protocolHandlersList of available ProtocolHandler . |
private ConcurrentLinkedQueue | protocolFindersList of available ProtocolFinder . |
private Map | mappedProtocolsList of available ProtocolFinder . |
private SSLContext | sslContextThe SSLContext used for handshaking. |
private boolean | isSetIs the protocol of this listener configured |
private boolean | isRequestedTransportSecureIs the protocol used secure. |
private ConcurrentLinkedQueue | puTasksA cached list of PUTask. |
private static Logger | loggerLogger |
Methods Summary |
---|
public void | addProtocolFinder(ProtocolFinder protocolFinder)Add an instance of ProtocolFinder
protocolFinders.offer(protocolFinder);
|
public void | addProtocolHandler(ProtocolHandler protocolHandler)Add an instance of ProtocolHandler
String[] protocols = protocolHandler.getProtocols();
for(String protocol: protocols){
protocolHandlers.put(protocol,protocolHandler);
}
|
public void | addTask(com.sun.enterprise.web.connector.grizzly.Task task)Seek for the TCP protocol used. First all ProtocolFinder will be invoked.
If the protocol is found, the associated ProtocolHandler will be executed.
The execution of this method will occurs on the same thread and the
main Selector (SelectorThread).
// Performance optimization used when a single protocol
// is supported by this Pipeline.
ProtocolHandler protocolHandler = null;
boolean cachedHandler = mappedProtocols != null
&& (protocolHandler =
mappedProtocols.get(task.getSelectionKey())) != null;
SelectorThread selectorThread = task.getSelectorThread();
KeepAlivePipeline kap = selectorThread == null ? null :
selectorThread.getKeepAlivePipeline();
if (protocolFinders.isEmpty()
|| kap == null
|| protocolHandlers.isEmpty()
|| task.getType() != Task.READ_TASK
|| (kap.isKeepAlive(task.getSelectionKey()) && !cachedHandler)){
super.addTask(task);
return;
}
task.getSelectionKey().attach(null);
if (!isSet) {
isRequestedTransportSecure =
(task.getSelectorThread() instanceof SecureSelector)
? true: false;
isSet = true;
if (isRequestedTransportSecure){
sslContext = ((SSLSelectorThread)task.getSelectorThread())
.getSSLContext();
}
if (!isRequestedTransportSecure || sslContext == null) {
if ( sslContext == null ){
Enumeration<SelectorThread> selectors
= SelectorThread.getSelectors();
SelectorThread sel;
while (selectors.hasMoreElements()){
sel = selectors.nextElement();
if (sel instanceof SSLSelectorThread){
sslContext =
((SSLSelectorThread)sel).getSSLContext();
if (sslContext != null)
break;
}
}
}
}
if (sslContext == null){
try{
SSLImplementation sslHelper = SSLImplementation.getInstance();
ServerSocketFactory serverSF =
sslHelper.getServerSocketFactory();
serverSF.setAttribute("keystoreType","JKS");
serverSF.setAttribute("keystore",
System.getProperty("javax.net.ssl.keyStore"));
serverSF.setAttribute("truststoreType","JKS");
serverSF.setAttribute("truststore",
System.getProperty("javax.net.ssl.trustStore"));
serverSF.init();
sslContext = serverSF.getSSLContext();
} catch(Throwable ex){
logger.log(Level.FINE,
"SSL not supported.",ex);
}
}
}
super.addTask(getPUTask((DefaultReadTask)task,protocolHandler));
|
public boolean | expireKey(java.nio.channels.SelectionKey key)Invoked when the SelectorThread is about to expire a SelectionKey.
ProtocolHandler ph = mappedProtocols.get(key);
if (ph != null){
return ph.expireKey(key);
} else {
return true;
}
|
private com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask | getPUTask(com.sun.enterprise.web.connector.grizzly.DefaultReadTask readTask, ProtocolHandler protocolHandler)
PUTask task = puTasks.poll();
if (task == null){
task = new PUTask();
}
task.readTask = readTask;
task.protocolHandler = protocolHandler;
task.setSelectionKey(readTask.getSelectionKey());
task.setSelectorThread(readTask.getSelectorThread());
return task;
|
private void | loadFinders()Load ProtocolFinder defined as a System property
(-Dcom.sun.enterprise.web.connector.grizzly.protocolFinders=... , ...)
if ( System.getProperty(PROTOCOL_FINDERS) != null){
StringTokenizer st = new StringTokenizer(
System.getProperty(PROTOCOL_FINDERS),",");
while (st.hasMoreTokens()){
ProtocolFinder protocolFinder = (ProtocolFinder)
loadInstance(st.nextToken());
protocolFinders.offer(protocolFinder);
}
}
|
private void | loadHandlers()Load ProtocolHandler defined as a System property
(-Dcom.sun.enterprise.web.connector.grizzly.protocolHandlers=... , ...)
if ( System.getProperty(PROTOCOL_HANDLERS) != null){
StringTokenizer st = new StringTokenizer(
System.getProperty(PROTOCOL_HANDLERS),",");
while (st.hasMoreTokens()){
ProtocolHandler protocolHandler = (ProtocolHandler)
loadInstance(st.nextToken());
if ( protocolHandler != null) {
String[] protocols = protocolHandler.getProtocols();
for(String protocol: protocols){
protocolHandlers.put(protocol,protocolHandler);
}
}
}
}
|
private java.lang.Object | loadInstance(java.lang.String property)Util to load classes using reflection.
Class className = null;
try{
className = Class.forName(property,true,
Thread.currentThread().getContextClassLoader());
return className.newInstance();
} catch (Throwable t) {
// Log me
}
return null;
|
public void | removeProtocolFinder(ProtocolFinder protocolFinder)Remove a ProtocolFinder
protocolFinders.remove(protocolFinder);
|
public void | removeProtocolHandler(ProtocolHandler protocolHandler)Remove a ProtocolHandler
String[] protocols = protocolHandler.getProtocols();
for(String protocol: protocols){
protocolHandlers.remove(protocol);
}
|