com.netbilling.direct
Class IdGenerator

java.lang.Object
  extended by com.netbilling.net.NetworkClient
      extended by com.netbilling.direct.IdGenerator

public class IdGenerator
extends NetworkClient

This class allows you to obtain unique ID numbers from the servers. It's recomended that you obtain a transaction ID prior to submitting the transaction for processing. This will allow you to later determine what happened to the transaction, even if you encounter a network error while waiting for the transaction response.


Nested Class Summary
static class IdGenerator.IdGeneratorException
          Failed to obtain ID number, the exception object will contain more information.
 
Field Summary
 
Fields inherited from class com.netbilling.net.NetworkClient
PROTOCOL_HTTP, PROTOCOL_HTTPS
 
Constructor Summary
IdGenerator()
          Create a new instance object of this class.
 
Method Summary
 java.lang.String obtainNewId()
          Returns 1 new unique ID.
protected  int obtainNewIds(java.lang.String[] out, int num)
          Obtain one or more unique ID number from the server.
 void setPerformanceMode(boolean yes)
          When using performance mode, a separate thread will be spawned.
 void setTimeout_ms(int milli_seconds)
          Set the network timeout for calls to obtainNewIds() in milli seconds.
 
Methods inherited from class com.netbilling.net.NetworkClient
getPort, getProtocol, getServer, getURL, setPath, setPort, setProtocol, setServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdGenerator

public IdGenerator()
Create a new instance object of this class. One object can safely be shared by multiple threads, provided you make sure setServer(), setProtocol() and setPerformanceMode() are not called while any other threads are using the object. Normally you only call those methods once, or not at all.

See Also:
NetworkClient.setProtocol(java.lang.String), NetworkClient.setServer(java.lang.String), setPerformanceMode(boolean)
Method Detail

setTimeout_ms

public void setTimeout_ms(int milli_seconds)
Set the network timeout for calls to obtainNewIds() in milli seconds. The default is 25000 (25 seconds).


setPerformanceMode

public void setPerformanceMode(boolean yes)
When using performance mode, a separate thread will be spawned. This thread will keep a pool of pre-allocated IDs ready, so that calls to obtainNewId() can be completed instantly. The size of the pool will be dynamically adjusted to match your usage rate.

NOTE: When using performance mode, you should only have 1 instance of this class, or you will end up with one background thread for each object instance.

See Also:
obtainNewId()

obtainNewIds

protected int obtainNewIds(java.lang.String[] out,
                           int num)
                    throws IdGenerator.IdGeneratorException
Obtain one or more unique ID number from the server.

Throws:
IdGenerator.IdGeneratorException

obtainNewId

public java.lang.String obtainNewId()
                             throws IdGenerator.IdGeneratorException
Returns 1 new unique ID. The ID is either obtained from the server, or from the local pool of pre-allocated IDs. This call is thread safe.

Throws:
IdGenerator.IdGeneratorException

Version 3.1.1

This is propriatary and confidential unpublished information. Copyright(c) 1999-2014, All rights reserved.