Overview | Package | Class | Tree | Deprecated | Index | Help
| JSS 3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mozilla.jss.util
Class NativeProxy

    java.lang.Object
      |
      +--org.mozilla.jss.util.NativeProxy

Direct Known Subclasses:
  CertProxy, CipherContextProxy, KeyProxy, ModuleProxy, SigContextProxy, SocketProxy, TokenProxy

public abstract class NativeProxy
extends java.lang.Object

NativeProxy, a superclass for Java classes that mirror C data structures. It contains some code to help make sure that native memory is getting freed properly.

Field Summary
`(package private) static java.util.Random` | `indexGenerator`
`private byte[]` | `mPointer` Byte array containing native pointer bytes.
`(package private) static java.util.Hashtable` | `registry`
`private long` | `registryIndex` Native Proxy Registry In debug mode, we keep track of all NativeProxy objects in a static registry.

Constructor Summary
`private` | `NativeProxy()` Default constructor.
`` | `NativeProxy(byte[] pointer)` Create a NativeProxy from a byte array representing a C pointer.

Method Summary
`static void` | `assertRegistryEmpty()` Assert that the Registry is empty.
`boolean` | `equals(java.lang.Object obj)` Deep comparison operator.
`protected void` | `finalize()` Finalize this NativeProxy by releasing its native resources.
`long` | `getRegistryIndex()`
`static java.util.Enumeration` | `getRegistryIndices()`
`private static long` | `register()` Register a NativeProxy instance.
`protected abstract void` | `releaseNativeResources()` Release the native resources used by this proxy.
`private static void` | `unregister(long index)` Unregister a NativeProxy instance.

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### mPointer

    private byte[] mPointer

  Byte array containing native pointer bytes.

### registryIndex

    private long registryIndex

  Native Proxy Registry

  In debug mode, we keep track of all NativeProxy objects in a static registry. Whenever a NativeProxy is constructed, it registers. Whenever it finalizes, it unregisters. At the end of the game, we should be able to garbage collect and then assert that the registry is empty. This could be done, for example, in the jssjava JVM after main() completes. This registration process verifies that people are calling NativeProxy.finalize() from their subclasses of NativeProxy, so that releaseNativeResources() gets called.

### registry

    static java.util.Hashtable registry

### indexGenerator

    static java.util.Random indexGenerator

Constructor Detail

### NativeProxy

    private NativeProxy()

  Default constructor. Should not be called.

### NativeProxy

    public NativeProxy(byte[] pointer)

  Create a NativeProxy from a byte array representing a C pointer. This is the only way to create a NativeProxy, it should be called from the constructor of your subclass.

Parameters:
  `pointer` - A byte array, created with JSS_ptrToByteArray, that contains a pointer pointing to a native data structure. The NativeProxy instance acts as a proxy for that native data structure.

Method Detail

### equals

    public boolean equals(java.lang.Object obj)

  Deep comparison operator.

  Overrides:
    `equals` in class `java.lang.Object`
  Returns:
    true if `obj` has the same underlying native pointer. false if the `obj` is null or has a different underlying native pointer.

### releaseNativeResources

    protected abstract void releaseNativeResources()

  Release the native resources used by this proxy. Subclasses of NativeProxy must define this method to clean up data structures in C code that are referenced by this proxy. releaseNativeResources() will usually be implemented as a native method.

  You don't call this method; NativeProxy.finalize() calls it for you.

  You must declare a finalize() method which calls super.finalize().

### finalize

    protected void finalize()
                     throws java.lang.Throwable

  Finalize this NativeProxy by releasing its native resources. The finalizer calls releaseNativeResources() so you don't have to. This finalizer should be called from the finalize() method of all subclasses: class MyProxy extends NativeProxy { [...] protected void finalize() throws Throwable { // do any object-specific finalization other than // releasing native resources [...] super.finalize(); } }

  Overrides:
    `finalize` in class `java.lang.Object`
    `java.lang.Throwable`

### register

    private static long register()

  Register a NativeProxy instance.

  Returns:
    The unique index of this object in the registry.

### unregister

    private static void unregister(long index)

  Unregister a NativeProxy instance.

  Parameters:
    `index` - The index of this object in the registry, as returned from the previous call to register().

### getRegistryIndices

    public static java.util.Enumeration getRegistryIndices()

  Returns:
    A list of the indices in the registry. Each element is a Long.
  See Also:
    `getRegistryIndex()`

### getRegistryIndex

    public long getRegistryIndex()

  Returns:
    The index of this NativeProxy in the NativeProxy registry.
  See Also:
    `getRegistryIndices()`

### assertRegistryEmpty

    public static void assertRegistryEmpty()

  Assert that the Registry is empty. Only works in debug mode; in ship mode, it is a no-op. If the Registry is not empty when this is called, an assertion (org.mozilla.jss.util.AssertionException) is thrown.

Overview | Package | Class | Tree | Deprecated | Index | Help
| JSS 3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD