org.norther.tammi.core.external
Class DefaultLibrary

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.external.DefaultLibrary
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Library
Direct Known Subclasses:
DefaultNativeRealm

public abstract class DefaultLibrary
extends Adaptee
implements Library

An abstract implementation of native Library. A set of native methods with different return values are provided. The per-thread specific JNI environment pointer may be optionally included as the first argument (or the second one if the first one is reserved for the result) in all native calls.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultLibrary()
          Constructs a new library.
DefaultLibrary(String library)
          Constructs a new library with a native library.
 
Method Summary
protected  void freeLibrary()
          Frees the native library.
 String getBinKey()
          Gets the path finder key for resolving binary paths.
protected  int getLibrary()
          Gets the library code.
 String getLibraryPath()
          Gets the path to the native library.
 String getLoaderPath()
          Gets the static path to the loader library.
protected  void invoke(String name, boolean env)
          Invokes a void library function.
protected  void invoke(String name, boolean env, Object args)
          Invokes a void library function with arguments.
protected  byte invokeByte(String name, boolean env)
          Invokes a byte library function.
protected  byte invokeByte(String name, boolean env, Object args)
          Invokes a byte library function with arguments.
protected  byte[] invokeBytes(String name, boolean env)
          Invokes a byte array library function.
protected  byte[] invokeBytes(String name, boolean env, Object args)
          Invokes a byte array library function with arguments.
protected  byte[] invokeConstBytes(String name, boolean env)
          Invokes a constant byte array library function.
protected  byte[] invokeConstBytes(String name, boolean env, Object args)
          Invokes a constant byte array library function with arguments.
protected  String invokeConstString(String name, boolean env)
          Invokes a constant string library function.
protected  String invokeConstString(String name, boolean env, Object args)
          Invokes a constant string library function with arguments.
protected  String[] invokeConstStrings(String name, boolean env)
          Invokes a constant string array library function.
protected  String[] invokeConstStrings(String name, boolean env, Object args)
          Invokes a constant string array library function with arguments.
protected  double invokeDouble(String name, boolean env)
          Invokes a double library function.
protected  double invokeDouble(String name, boolean env, Object args)
          Invokes a double library function with arguments.
protected  float invokeFloat(String name, boolean env)
          Invokes a float library function.
protected  float invokeFloat(String name, boolean env, Object args)
          Invokes a float library function with arguments.
protected  int invokeInt(String name, boolean env)
          Invokes an integer library function.
protected  int invokeInt(String name, boolean env, Object args)
          Invokes an integer library function with arguments.
protected  long invokeLong(String name, boolean env)
          Invokes a long library function.
protected  long invokeLong(String name, boolean env, Object args)
          Invokes a long integer library function with arguments.
protected  short invokeShort(String name, boolean env)
          Invokes a short library function.
protected  short invokeShort(String name, boolean env, Object args)
          Invokes a short library function with arguments.
protected  String invokeString(String name, boolean env)
          Invokes a string library function.
protected  String invokeString(String name, boolean env, Object args)
          Invokes a string library function with arguments.
protected  String[] invokeStrings(String name, boolean env)
          Invokes a string array library function.
protected  String[] invokeStrings(String name, boolean env, Object args)
          Invokes a string array library function with arguments.
 void setBinKey(String key)
          Sets the path finder key for resolving binary paths.
 void setLibraryPath(String path)
          Sets the path to the native library.
 void setLoaderPath(String path)
          Sets the static path to the loader library.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLibrary

public DefaultLibrary()
Constructs a new library.


DefaultLibrary

public DefaultLibrary(String library)
Constructs a new library with a native library.

Parameters:
library - the path to the native library.
Method Detail

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

getBinKey

public String getBinKey()
Description copied from interface: Library
Gets the path finder key for resolving binary paths.

Specified by:
getBinKey in interface Library
Returns:
the path finder key.

setBinKey

public void setBinKey(String key)
Description copied from interface: Library
Sets the path finder key for resolving binary paths. The default key is PathFinderMBean.BIN.

Specified by:
setBinKey in interface Library
Parameters:
key - the path finder key.

getLoaderPath

public String getLoaderPath()
Description copied from interface: Library
Gets the static path to the loader library.

Specified by:
getLoaderPath in interface Library
Returns:
the path to the loader library.

setLoaderPath

public void setLoaderPath(String path)
                   throws LogException
Description copied from interface: Library
Sets the static path to the loader library.

Specified by:
setLoaderPath in interface Library
Parameters:
path - the path to the loader library.
Throws:
LogException - if the library cannot be set.

getLibraryPath

public String getLibraryPath()
Description copied from interface: Library
Gets the path to the native library.

Specified by:
getLibraryPath in interface Library
Returns:
the path to the native library.

setLibraryPath

public void setLibraryPath(String path)
Description copied from interface: Library
Sets the path to the native library.

Specified by:
setLibraryPath in interface Library
Parameters:
path - the path to the native library.

getLibrary

protected int getLibrary()
Gets the library code.

Returns:
the library code.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

freeLibrary

protected void freeLibrary()
Frees the native library.


invoke

protected void invoke(String name,
                      boolean env)
Invokes a void library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invoke

protected void invoke(String name,
                      boolean env,
                      Object args)
Invokes a void library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeByte

protected byte invokeByte(String name,
                          boolean env)
Invokes a byte library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a byte.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeByte

protected byte invokeByte(String name,
                          boolean env,
                          Object args)
Invokes a byte library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a byte.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeShort

protected short invokeShort(String name,
                            boolean env)
Invokes a short library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a short.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeShort

protected short invokeShort(String name,
                            boolean env,
                            Object args)
Invokes a short library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a short.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeInt

protected int invokeInt(String name,
                        boolean env)
Invokes an integer library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
an integer.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeInt

protected int invokeInt(String name,
                        boolean env,
                        Object args)
Invokes an integer library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
an integer.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeLong

protected long invokeLong(String name,
                          boolean env)
Invokes a long library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a long integer.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeLong

protected long invokeLong(String name,
                          boolean env,
                          Object args)
Invokes a long integer library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a long integer.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeFloat

protected float invokeFloat(String name,
                            boolean env)
Invokes a float library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a float.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeFloat

protected float invokeFloat(String name,
                            boolean env,
                            Object args)
Invokes a float library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a float.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeDouble

protected double invokeDouble(String name,
                              boolean env)
Invokes a double library function.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a double.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeDouble

protected double invokeDouble(String name,
                              boolean env,
                              Object args)
Invokes a double library function with arguments.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a double.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeString

protected String invokeString(String name,
                              boolean env)
Invokes a string library function.

The native result string will be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a string.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeString

protected String invokeString(String name,
                              boolean env,
                              Object args)
Invokes a string library function with arguments.

The native result string will be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a string.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstString

protected String invokeConstString(String name,
                                   boolean env)
Invokes a constant string library function.

The native result string will not be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a string.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstString

protected String invokeConstString(String name,
                                   boolean env,
                                   Object args)
Invokes a constant string library function with arguments.

The native result string will not be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a string.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeBytes

protected byte[] invokeBytes(String name,
                             boolean env)
Invokes a byte array library function. The native function must return the size of the allocated array as its value and the byte array in its first parameter.

The native result array will be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a byte array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeBytes

protected byte[] invokeBytes(String name,
                             boolean env,
                             Object args)
Invokes a byte array library function with arguments. The native function must return the size of the allocated array as its value and the byte array in its first parameter.

The native result array will be freed by the invoker.

The result parameter must not be included in the argument array.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a byte array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstBytes

protected byte[] invokeConstBytes(String name,
                                  boolean env)
Invokes a constant byte array library function. The native function must return the size of the allocated array as its value and the byte array in its first parameter.

The native result array will not be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a byte array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstBytes

protected byte[] invokeConstBytes(String name,
                                  boolean env,
                                  Object args)
Invokes a constant byte array library function with arguments. The native function must return the size of the allocated array as its value and the byte array in its first parameter.

The native result array will be freed by the invoker.

The result parameter must not be included in the argument array.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a byte array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeStrings

protected String[] invokeStrings(String name,
                                 boolean env)
Invokes a string array library function. The native function must return the size of the allocated array as its value and the string array in its first parameter.

The native result array and array elements will be freed by the invoker.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a string array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeStrings

protected String[] invokeStrings(String name,
                                 boolean env,
                                 Object args)
Invokes a string array library function with arguments. The native function must return the size of the allocated array as its value and the string array in its first parameter.

The native result array and array elements will be freed by the invoker.

The result parameter must not be included in the argument array.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a string array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstStrings

protected String[] invokeConstStrings(String name,
                                      boolean env)
Invokes a constant string array library function. The native function must return the size of the allocated array as its value and the string array in its first parameter.

The native result array will be freed by the invoker, but array elements will not be freed.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
Returns:
a string array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.

invokeConstStrings

protected String[] invokeConstStrings(String name,
                                      boolean env,
                                      Object args)
Invokes a constant string array library function with arguments. The native function must return the size of the allocated array as its value and the string array in its first parameter.

The native result array will be freed by the invoker, but array elements will not be freed.

The result parameter must not be included in the argument array.

Parameters:
name - the name of the method.
env - if true, include the enviroment.
args - primitive, string and array arguments.
Returns:
a string array.
Throws:
UnsatisfiedLinkError - if no loader.
NullPointerException - if no library.
IllegalArgumentException - if not available.
UnsupportedOperationException - if failed to initialize.


Copyright © 2004 The Norther Organization. All rights reserved.