org.elkoserver.server.workshop.bank.client
Class BankClient

java.lang.Object
  extended by org.elkoserver.foundation.actor.BasicProtocolHandler
      extended by org.elkoserver.server.context.AdminObject
          extended by org.elkoserver.server.workshop.bank.client.BankClient
All Implemented Interfaces:
DispatchTarget, Referenceable, InternalObject, ArgRunnable

public class BankClient
extends AdminObject
implements ArgRunnable

Internal object that acts as a client for the external 'bank' service.


Nested Class Summary
static class BankClient.AccountDesc
          A struct describing an account, returned as part of the results from query accounts.
static class BankClient.AccountResultHandler
          Result handler class for requests that return an account ref (delete account, freeze account, and unfreeze account).
static class BankClient.AccountsResultHandler
          Result handler class for requests that return an array of account refs (make accounts).
static class BankClient.BalanceResultHandler
          Result handler class for requests that affect an account balance (mint, unmint, and unmintEncmbrance).
static class BankClient.BankReplyHandler
          Base class for request-specific handlers for replies from the bank.
static class BankClient.CurrencyResultHandler
          Result handler class for the make currency request.
static class BankClient.EncumberResultHandler
          Result handler class for the encumber request.
static class BankClient.EncumbranceDesc
          A struct describing an encumbrance, returned as part of the results from query accounts.
static class BankClient.KeyResultHandler
          Result handler class for request that return a key (cancel key, duplicate key, issue root key, and make key).
static class BankClient.QueryAccountsResultHandler
          Result handler class for the query account request.
static class BankClient.QueryCurrenciesResultHandler
          Result handler class for the query currencies request.
static class BankClient.QueryEncumbranceResultHandler
          Result handler class for the query encumbrance request.
static class BankClient.ReleaseResultHandler
          Result handler class for the release request.
static class BankClient.TransferResultHandler
          Result handler class for transfer requests (transfer and transferEncumbrance).
 
Constructor Summary
BankClient(String serviceName)
          Constructor.
 
Method Summary
 void activate(String ref, Contextor contextor)
          Make this object live inside the context server.
 void cancelkey(ServiceActor from, String xid, OptString fail, OptString desc, OptString optCancel)
          JSON message handler for the response to a cancel key request.
 void cancelKey(String key, String memo, String cancel, BankClient.KeyResultHandler resultHandler)
          Cancel an authorization key.
 void deleteaccount(ServiceActor from, String xid, OptString fail, OptString desc, OptString optAccount)
          JSON message handler for the response to a delete account request.
 void deleteAccount(String key, String memo, String account, BankClient.AccountResultHandler resultHandler)
          Delete an account.
 void dupkey(ServiceActor from, String xid, OptString fail, OptString desc, OptString optNewkey)
          JSON message handler for the response to a duplicate key request.
 void dupKey(String key, String memo, String expires, BankClient.KeyResultHandler resultHandler)
          Duplicate an authorization key.
 void encumber(ServiceActor from, String xid, OptString fail, OptString desc, OptString optEnc, OptInteger optSrcbal)
          JSON message handler for the response to an encumber request.
 void encumber(String key, String memo, String src, int amount, long expiration, BankClient.EncumberResultHandler resultHandler)
          Encumber an account, i.e., provisionally reserve funds for a fuure transaction.
 void freezeaccount(ServiceActor from, String xid, OptString fail, OptString desc, OptString optAccount)
          JSON message handler for the response to a freeze account request.
 void freezeAccount(String key, String memo, String account, BankClient.AccountResultHandler resultHandler)
          Freeze an account, rendering it temporarily unable to participate in transactions.
 void issueRootKey(BankClient.KeyResultHandler resultHandler)
          Obtain the bank's root key, if nobody yet has it.
 void issuerootkey(ServiceActor from, String xid, OptString fail, OptString desc, OptString optRootkey)
          JSON message handler for the response to an issue root key request.
 void makeaccounts(ServiceActor from, String xid, OptString fail, OptString desc, String[] accounts)
          JSON message handler for the response to a make account request.
 void makeAccounts(String key, String memo, String[] currencies, String owner, BankClient.AccountsResultHandler resultHandler)
          Create a set of new accounts.
 void makecurrency(ServiceActor from, String xid, OptString fail, OptString desc, OptString optCurrency)
          JSON message handler for the response to a make currency request.
 void makeCurrency(String key, String memo, String currency, BankClient.CurrencyResultHandler resultHandler)
          Create a new currency.
 void makekey(ServiceActor from, String xid, OptString fail, OptString desc, OptString optNewkey)
          JSON message handler for the response to a make key request.
 void makeKey(String key, String memo, String type, String currency, String expires, BankClient.KeyResultHandler resultHandler)
          Create a new authorization key.
 void mint(ServiceActor from, String xid, OptString fail, OptString desc, OptString optDst, OptInteger optDstbal)
          JSON message handler for the response to a mint request.
 void mint(String key, String memo, String dst, int amount, BankClient.BalanceResultHandler resultHandler)
          Create money into an accont.
 void queryaccounts(ServiceActor from, String xid, OptString fail, OptString desc, BankClient.AccountDesc[] accounts)
          JSON message handler for the response to a query account request.
 void queryAccounts(String key, String memo, String[] accounts, boolean encs, BankClient.QueryAccountsResultHandler resultHandler)
          Get information about an account.
 void querycurrencies(ServiceActor from, String xid, OptString fail, OptString desc, Currency[] currencies)
          JSON message handler for the response to a query currencies request.
 void queryCurrencies(String key, String memo, BankClient.QueryCurrenciesResultHandler resultHandler)
          Get information about extant currencies.
 void queryenc(ServiceActor from, String xid, OptString fail, OptString desc, OptString optEnc, OptString optCurr, OptString optAccount, OptInteger optAmount, OptString optExpires, OptString optMemo)
          JSON message handler for the response to a query encumbrance request.
 void queryEncumbrance(String key, String memo, String enc, BankClient.QueryEncumbranceResultHandler resultHandler)
          Get information about an encumbrance.
 void releaseenc(ServiceActor from, String xid, OptString fail, OptString desc, OptString optSrc, OptInteger optSrcbal, OptBoolean optActive)
          JSON message handler for the response to a release encumbrance request.
 void releaseEncumbrance(String key, String memo, String enc, BankClient.ReleaseResultHandler resultHandler)
          Release a previous encumbrance on an account.
 void run(Object obj)
          Callback that is invoked when the service connection is established or fails to be established.
 String status()
          Get the current status of the connection to the external service.
 void transfer(String key, String memo, String src, String dst, int amount, BankClient.TransferResultHandler resultHandler)
          Transfer money from one account to another.
 void transferEncumbrance(String key, String memo, String enc, String dst, BankClient.TransferResultHandler resultHandler)
          Transfer encumbered funds into another account.
 void unfreezeaccount(ServiceActor from, String xid, OptString fail, OptString desc, OptString optAccount)
          JSON message handler for the response to an unfreeze account request.
 void unfreezeAccount(String key, String memo, String account, BankClient.AccountResultHandler resultHandler)
          Unfreeze an account, rendering it once again able to participate in transactions.
 void unmint(ServiceActor from, String xid, OptString fail, OptString desc, OptString optSrc, OptInteger optSrcbal)
          JSON message handler for the response to an unmint request.
 void unmint(String key, String memo, String src, int amount, BankClient.BalanceResultHandler resultHandler)
          Destroy money from an account.
 void unmintenc(ServiceActor from, String xid, OptString fail, OptString desc, OptString optSrc, OptInteger optSrcbal)
          JSON message handler for the response to an unmint encumbrance request.
 void unmintEncumbrance(String key, String memo, String enc, BankClient.BalanceResultHandler resultHandler)
          Destroy encumbered funds.
 void xfer(ServiceActor from, String xid, OptString fail, OptString desc, OptString optSrc, OptInteger optSrcbal, OptString optDst, OptInteger optDstbal)
          JSON message handler for the response to a transfer request.
 void xferenc(ServiceActor from, String xid, OptString fail, OptString desc, OptString optSrc, OptInteger optSrcbal, OptString optDst, OptInteger optDstbal)
          JSON message handler for the response to a transfer encumbrance request.
 
Methods inherited from class org.elkoserver.server.context.AdminObject
contextor, ref
 
Methods inherited from class org.elkoserver.foundation.actor.BasicProtocolHandler
auth, debug, disconnect, ping, pong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BankClient

@JSONMethod(value="servicename")
public BankClient(String serviceName)
Constructor.

Method Detail

activate

public void activate(String ref,
                     Contextor contextor)
Make this object live inside the context server. In this case we initiate a connection to the external bank service.

Specified by:
activate in interface InternalObject
Overrides:
activate in class AdminObject
Parameters:
ref - Reference string identifying this object in the static object table.
contextor - The contextor for this server.

run

public void run(Object obj)
Callback that is invoked when the service connection is established or fails to be established.

Specified by:
run in interface ArgRunnable
Parameters:
obj - The connection to the bank service, or null if connection setup failed.

status

public String status()
Get the current status of the connection to the external service.

Returns:
a tag string describing the current connection state.

cancelKey

public void cancelKey(String key,
                      String memo,
                      String cancel,
                      BankClient.KeyResultHandler resultHandler)
Cancel an authorization key.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
cancel - Ref of key to be cancelled.
resultHandler - Callback to be invoked on the result.

deleteAccount

public void deleteAccount(String key,
                          String memo,
                          String account,
                          BankClient.AccountResultHandler resultHandler)
Delete an account.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
account - Ref of account to be deleted.
resultHandler - Callback to be invoked on the result.

dupKey

public void dupKey(String key,
                   String memo,
                   String expires,
                   BankClient.KeyResultHandler resultHandler)
Duplicate an authorization key.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
expires - Expiration time for the new key.
resultHandler - Callback to be invoked on the result.

encumber

public void encumber(String key,
                     String memo,
                     String src,
                     int amount,
                     long expiration,
                     BankClient.EncumberResultHandler resultHandler)
Encumber an account, i.e., provisionally reserve funds for a fuure transaction.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
src - Ref of account to be encumbered.
amount - Quantity of funds to encumber.
expiration - Expiration time for encumbrance.
resultHandler - Callback to be invoked on the result.

freezeAccount

public void freezeAccount(String key,
                          String memo,
                          String account,
                          BankClient.AccountResultHandler resultHandler)
Freeze an account, rendering it temporarily unable to participate in transactions.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
account - Ref of account to be frozen.
resultHandler - Callback to be invoked on the result.

issueRootKey

public void issueRootKey(BankClient.KeyResultHandler resultHandler)
Obtain the bank's root key, if nobody yet has it.

Parameters:
resultHandler - Callback to be invoked on the result.

makeAccounts

public void makeAccounts(String key,
                         String memo,
                         String[] currencies,
                         String owner,
                         BankClient.AccountsResultHandler resultHandler)
Create a set of new accounts.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
currencies - Currencies in which the new accounts will be denominated.
owner - Ref of the account owner.
resultHandler - Callback to be invoked on the result.

makeCurrency

public void makeCurrency(String key,
                         String memo,
                         String currency,
                         BankClient.CurrencyResultHandler resultHandler)
Create a new currency.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
currency - Name for the new currency.
resultHandler - Callback to be invoked on the result.

makeKey

public void makeKey(String key,
                    String memo,
                    String type,
                    String currency,
                    String expires,
                    BankClient.KeyResultHandler resultHandler)
Create a new authorization key.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
type - Type of authorization new key should grant.
currency - Optioal name of currency scoping new key's authority, or null.
expires - Expiration time for the new key.
resultHandler - Callback to be invoked on the result.

mint

public void mint(String key,
                 String memo,
                 String dst,
                 int amount,
                 BankClient.BalanceResultHandler resultHandler)
Create money into an accont.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
dst - Ref of account to receive the funds.
amount - Quantity of money to create.
resultHandler - Callback to be invoked on the result.

queryAccounts

public void queryAccounts(String key,
                          String memo,
                          String[] accounts,
                          boolean encs,
                          BankClient.QueryAccountsResultHandler resultHandler)
Get information about an account.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
account - Ref of the account being queried.
encs - Flag that is true if the results should also include information about extant encumbrances on the account.
resultHandler - Callback to be invoked on the result.

queryCurrencies

public void queryCurrencies(String key,
                            String memo,
                            BankClient.QueryCurrenciesResultHandler resultHandler)
Get information about extant currencies.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
resultHandler - Callback to be invoked on the result.

queryEncumbrance

public void queryEncumbrance(String key,
                             String memo,
                             String enc,
                             BankClient.QueryEncumbranceResultHandler resultHandler)
Get information about an encumbrance.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
enc - Ref of the enumbrance being queried.
resultHandler - Callback to be invoked on the result.

releaseEncumbrance

public void releaseEncumbrance(String key,
                               String memo,
                               String enc,
                               BankClient.ReleaseResultHandler resultHandler)
Release a previous encumbrance on an account.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
enc - Ref of the encumbrance to be released
resultHandler - Callback to be invoked on the result.

transfer

public void transfer(String key,
                     String memo,
                     String src,
                     String dst,
                     int amount,
                     BankClient.TransferResultHandler resultHandler)
Transfer money from one account to another.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
src - Ref of source account.
dst - Ref of destination account.
amount - Quantity of funds to transfer.
resultHandler - Callback to be invoked on the result.

transferEncumbrance

public void transferEncumbrance(String key,
                                String memo,
                                String enc,
                                String dst,
                                BankClient.TransferResultHandler resultHandler)
Transfer encumbered funds into another account.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
enc - Encumbrance that is the source of funds.
dst - Ref of destination account.
resultHandler - Callback to be invoked on the result.

unfreezeAccount

public void unfreezeAccount(String key,
                            String memo,
                            String account,
                            BankClient.AccountResultHandler resultHandler)
Unfreeze an account, rendering it once again able to participate in transactions.

Parameters:
key - Authorizing key.
memo - Transaction annotation.
account - Ref of account to be frozen.
resultHandler - Callback to be invoked on the result.

unmint

public void unmint(String key,
                   String memo,
                   String src,
                   int amount,
                   BankClient.BalanceResultHandler resultHandler)
Destroy money from an account.

Parameters:
key - Authorizing key.
memo - Transaction annotation
src - Ref of account to lose the funds.
amount - Quantity of money to destroy.
resultHandler - Callback to be invoked on the result.

unmintEncumbrance

public void unmintEncumbrance(String key,
                              String memo,
                              String enc,
                              BankClient.BalanceResultHandler resultHandler)
Destroy encumbered funds.

Parameters:
key - Authorizing key.
memo - Transaction annotation
src - Ref of encumbrance that reserves the funds to be destroyed.
resultHandler - Callback to be invoked on the result.

cancelkey

@JSONMethod(value={"xid","fail","desc","cancel"})
public void cancelkey(ServiceActor from,
                                      String xid,
                                      OptString fail,
                                      OptString desc,
                                      OptString optCancel)
JSON message handler for the response to a cancel key request.


deleteaccount

@JSONMethod(value={"xid","fail","desc","account"})
public void deleteaccount(ServiceActor from,
                                          String xid,
                                          OptString fail,
                                          OptString desc,
                                          OptString optAccount)
JSON message handler for the response to a delete account request.


dupkey

@JSONMethod(value={"xid","fail","desc","newkey"})
public void dupkey(ServiceActor from,
                                   String xid,
                                   OptString fail,
                                   OptString desc,
                                   OptString optNewkey)
JSON message handler for the response to a duplicate key request.


encumber

@JSONMethod(value={"xid","fail","desc","enc","srcbal"})
public void encumber(ServiceActor from,
                                     String xid,
                                     OptString fail,
                                     OptString desc,
                                     OptString optEnc,
                                     OptInteger optSrcbal)
JSON message handler for the response to an encumber request.


freezeaccount

@JSONMethod(value={"xid","fail","desc","account"})
public void freezeaccount(ServiceActor from,
                                          String xid,
                                          OptString fail,
                                          OptString desc,
                                          OptString optAccount)
JSON message handler for the response to a freeze account request.


issuerootkey

@JSONMethod(value={"xid","fail","desc","rootkey"})
public void issuerootkey(ServiceActor from,
                                         String xid,
                                         OptString fail,
                                         OptString desc,
                                         OptString optRootkey)
JSON message handler for the response to an issue root key request.


makeaccounts

@JSONMethod(value={"xid","fail","desc","?accounts"})
public void makeaccounts(ServiceActor from,
                                         String xid,
                                         OptString fail,
                                         OptString desc,
                                         String[] accounts)
JSON message handler for the response to a make account request.


makecurrency

@JSONMethod(value={"xid","fail","desc","currency"})
public void makecurrency(ServiceActor from,
                                         String xid,
                                         OptString fail,
                                         OptString desc,
                                         OptString optCurrency)
JSON message handler for the response to a make currency request.


makekey

@JSONMethod(value={"xid","fail","desc","newkey"})
public void makekey(ServiceActor from,
                                    String xid,
                                    OptString fail,
                                    OptString desc,
                                    OptString optNewkey)
JSON message handler for the response to a make key request.


mint

@JSONMethod(value={"xid","fail","desc","dst","dstbal"})
public void mint(ServiceActor from,
                                 String xid,
                                 OptString fail,
                                 OptString desc,
                                 OptString optDst,
                                 OptInteger optDstbal)
JSON message handler for the response to a mint request.


queryaccounts

@JSONMethod(value={"xid","fail","desc","?accounts"})
public void queryaccounts(ServiceActor from,
                                          String xid,
                                          OptString fail,
                                          OptString desc,
                                          BankClient.AccountDesc[] accounts)
JSON message handler for the response to a query account request.


querycurrencies

@JSONMethod(value={"xid","fail","desc","?currencies"})
public void querycurrencies(ServiceActor from,
                                            String xid,
                                            OptString fail,
                                            OptString desc,
                                            Currency[] currencies)
JSON message handler for the response to a query currencies request.


queryenc

@JSONMethod(value={"xid","fail","desc","enc","curr","account","amount","expires","memo"})
public void queryenc(ServiceActor from,
                                     String xid,
                                     OptString fail,
                                     OptString desc,
                                     OptString optEnc,
                                     OptString optCurr,
                                     OptString optAccount,
                                     OptInteger optAmount,
                                     OptString optExpires,
                                     OptString optMemo)
JSON message handler for the response to a query encumbrance request.


releaseenc

@JSONMethod(value={"xid","fail","desc","src","srcbal","active"})
public void releaseenc(ServiceActor from,
                                       String xid,
                                       OptString fail,
                                       OptString desc,
                                       OptString optSrc,
                                       OptInteger optSrcbal,
                                       OptBoolean optActive)
JSON message handler for the response to a release encumbrance request.


unfreezeaccount

@JSONMethod(value={"xid","fail","desc","account"})
public void unfreezeaccount(ServiceActor from,
                                            String xid,
                                            OptString fail,
                                            OptString desc,
                                            OptString optAccount)
JSON message handler for the response to an unfreeze account request.


unmint

@JSONMethod(value={"xid","fail","desc","src","srcbal"})
public void unmint(ServiceActor from,
                                   String xid,
                                   OptString fail,
                                   OptString desc,
                                   OptString optSrc,
                                   OptInteger optSrcbal)
JSON message handler for the response to an unmint request.


unmintenc

@JSONMethod(value={"xid","fail","desc","src","srcbal"})
public void unmintenc(ServiceActor from,
                                      String xid,
                                      OptString fail,
                                      OptString desc,
                                      OptString optSrc,
                                      OptInteger optSrcbal)
JSON message handler for the response to an unmint encumbrance request.


xfer

@JSONMethod(value={"xid","fail","desc","src","srcbal","dst","dstbal"})
public void xfer(ServiceActor from,
                                 String xid,
                                 OptString fail,
                                 OptString desc,
                                 OptString optSrc,
                                 OptInteger optSrcbal,
                                 OptString optDst,
                                 OptInteger optDstbal)
JSON message handler for the response to a transfer request.


xferenc

@JSONMethod(value={"xid","fail","desc","src","srcbal","dst","dstbal"})
public void xferenc(ServiceActor from,
                                    String xid,
                                    OptString fail,
                                    OptString desc,
                                    OptString optSrc,
                                    OptInteger optSrcbal,
                                    OptString optDst,
                                    OptInteger optDstbal)
JSON message handler for the response to a transfer encumbrance request.