com.sun.grizzly.osgi.httpservice
Class OSGiMainAdapter

java.lang.Object
  extended by com.sun.grizzly.tcp.StaticResourcesAdapter
      extended by com.sun.grizzly.tcp.http11.GrizzlyAdapter
          extended by com.sun.grizzly.osgi.httpservice.OSGiMainAdapter
All Implemented Interfaces:
OSGiGrizzlyAdapter, Adapter

public class OSGiMainAdapter
extends GrizzlyAdapter
implements OSGiGrizzlyAdapter

OSGi Main Adapter.

Dispatching adapter. Grizzly integration.

Responsibilities:

Author:
Hubert Iwaniuk

Field Summary
 
Fields inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
ADAPTER_NOTES, ALLOW_BACKSLASH, chunkingDisabled
 
Fields inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
cache, commitErrorResponse, fileFolders, resourcesContextPath
 
Constructor Summary
OSGiMainAdapter(Logger logger, org.osgi.framework.Bundle bundle)
          Constructor.
 
Method Summary
 ReentrantReadWriteLock.ReadLock getProcessingLock()
          Processing lock.
 ReentrantReadWriteLock.WriteLock getRemovalLock()
          Removal lock.
 void registerResourceAdapter(String alias, org.osgi.service.http.HttpContext context, String internalPrefix, org.osgi.service.http.HttpService httpService)
          Registers OSGiResourceAdapter in OSGi Http Service.
 void registerServletAdapter(String alias, javax.servlet.Servlet servlet, Dictionary initparams, org.osgi.service.http.HttpContext context, org.osgi.service.http.HttpService httpService)
          Registers OSGiServletAdapter in OSGi Http Service.
 void service(GrizzlyRequest request, GrizzlyResponse response)
          Service method dispatching to registered handlers.
 void unregisterAlias(String alias)
          Unregisters previously registered alias.
 void unregisterAll()
          Part of Shutdown sequence.
 void uregisterAllLocal()
          Unregisters all aliases registered by owning bundle.
 
Methods inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
afterService, afterService, destroy, getName, isAllowEncodedSlash, isDecodeURL, isHandleStaticResources, service, setAllowEncodedSlash, setDecodeUrl, setDispatcherHelper, setHandleStaticResources, start
 
Methods inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
addRootFolder, customizedErrorPage, getDefaultContentType, getResourcesContextPath, getRootFolder, getRootFolders, initWebDir, isUseSendFile, service, setDefaultContentType, setLogger, setResourcesContextPath, setRootFolder, setUseSendFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSGiMainAdapter

public OSGiMainAdapter(Logger logger,
                       org.osgi.framework.Bundle bundle)
Constructor.

Parameters:
logger - Logger utility.
bundle - Bundle that we create if for, for local data reference.
Method Detail

service

public void service(GrizzlyRequest request,
                    GrizzlyResponse response)
             throws Exception
Service method dispatching to registered handlers.

This method should contains the logic for any http extension to the Grizzly HTTP Webserver.

Specified by:
service in class GrizzlyAdapter
Parameters:
request - The GrizzlyRequest
response - The GrizzlyResponse
Throws:
Exception

registerServletAdapter

public void registerServletAdapter(String alias,
                                   javax.servlet.Servlet servlet,
                                   Dictionary initparams,
                                   org.osgi.service.http.HttpContext context,
                                   org.osgi.service.http.HttpService httpService)
                            throws org.osgi.service.http.NamespaceException,
                                   javax.servlet.ServletException
Registers OSGiServletAdapter in OSGi Http Service.

Keeps truck of all registrations, takes care of thread safety.

Parameters:
alias - Alias to register, if wrong value than throws NamespaceException.
servlet - Servlet to register under alias, if fails to Servlet.init(javax.servlet.ServletConfig) throws ServletException.
initparams - Initial parameters to populate ServletContext with.
context - OSGi HttpContext, provides mime handling, security and bundle specific resource access.
httpService - Used to HttpService.createDefaultHttpContext() if needed.
Throws:
org.osgi.service.http.NamespaceException - If alias was invalid or already registered.
javax.servlet.ServletException - If Servlet.init(javax.servlet.ServletConfig) fails.

registerResourceAdapter

public void registerResourceAdapter(String alias,
                                    org.osgi.service.http.HttpContext context,
                                    String internalPrefix,
                                    org.osgi.service.http.HttpService httpService)
                             throws org.osgi.service.http.NamespaceException
Registers OSGiResourceAdapter in OSGi Http Service.

Keeps truck of all registrations, takes care of thread safety.

Parameters:
alias - Alias to register, if wrong value than throws NamespaceException.
context - OSGi HttpContext, provides mime handling, security and bundle specific resource access.
internalPrefix - Prefix to map request for this alias to.
httpService - Used to HttpService.createDefaultHttpContext() if needed.
Throws:
org.osgi.service.http.NamespaceException - If alias was invalid or already registered.

unregisterAlias

public void unregisterAlias(String alias)
Unregisters previously registered alias.

Keeps truck of all registrations, takes care of thread safety.

Parameters:
alias - Alias to unregister, if not owning alias IllegalArgumentException is thrown.
Throws:
IllegalArgumentException - If alias was not registered by calling bundle.

uregisterAllLocal

public void uregisterAllLocal()
Unregisters all aliases registered by owning bundle.


unregisterAll

public void unregisterAll()
Part of Shutdown sequence. Unregister and clean up.


getProcessingLock

public ReentrantReadWriteLock.ReadLock getProcessingLock()
Processing lock.

ReentrantReadWriteLock.ReadLock can be obtained by concurrent threads at the same time.

Specified by:
getProcessingLock in interface OSGiGrizzlyAdapter
Returns:
Processing lock.

getRemovalLock

public ReentrantReadWriteLock.WriteLock getRemovalLock()
Removal lock.

ReentrantReadWriteLock.WriteLock can be obtained only by one thread, blocks OSGiGrizzlyAdapter.getProcessingLock().

Specified by:
getRemovalLock in interface OSGiGrizzlyAdapter
Returns:
Removal lock.
See Also:
OSGiGrizzlyAdapter.getProcessingLock(), ReentrantReadWriteLock.WriteLock


Copyright © 2013 Oracle Corporation. All Rights Reserved.