📄 peerprovider.java
字号:
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Copyrights:
*
* Copyright - 1999 Sun Microsystems, Inc. All rights reserved.
* 901 San Antonio Road, Palo Alto, California 94043, U.S.A.
*
* This product and related documentation are protected by copyright and
* distributed under licenses restricting its use, copying, distribution, and
* decompilation. No part of this product or related documentation may be
* reproduced in any form by any means without prior written authorization of
* Sun and its licensors, if any.
*
* RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United
* States Government is subject to the restrictions set forth in DFARS
* 252.227-7013 (c)(1)(ii) and FAR 52.227-19.
*
* The product described in this manual may be protected by one or more U.S.
* patents, foreign patents, or pending applications.
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Author:
*
* AePONA Limited, Interpoint Building
* 20-24 York Street, Belfast BT15 1AQ
* N. Ireland.
*
*
* Module Name : JAIN TCAP RI
* File Name : PeerProvider.java
* Author : Aidan Mc Gowan + Colm Hayden [Aepona]
* Eugene Bell [AePONA]
* Approver : Aepona JAIN Team
* Version : 1.1
* Notes :
*
* HISTORY
* Version Date Author Comments
* 1.0 19/03/99 AMcG, CH Initial version
* 1.0d 15/8/2000 Eugene Bell Final Public Release
* 1.1 26/4/2001 Eugene Bell Maintenance Release 1.1
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package com.aepona.jain.protocol.ss7.tcap;
import java.util.Vector;
import java.util.Hashtable;
import java.util.TooManyListenersException;
import java.util.*;
import jain.*;
import jain.protocol.ss7.tcap.TcapUserAddress;
import jain.protocol.ss7.tcap.JainTcapProvider;
import jain.protocol.ss7.tcap.JainTcapListener;
import jain.protocol.ss7.tcap.JainTcapStack;
import jain.protocol.ss7.tcap.ComponentIndEvent;
import jain.protocol.ss7.tcap.DialogueIndEvent;
import jain.protocol.ss7.tcap.ComponentReqEvent;
import jain.protocol.ss7.tcap.DialogueReqEvent;
import jain.ParameterNotSetException;
import jain.MandatoryParameterNotSetException;
import jain.protocol.ss7.tcap.ProviderNotAttachedException;
import jain.protocol.ss7.tcap.component.*;
import jain.protocol.ss7.tcap.dialogue.*;
import jain.protocol.ss7.*;
/**
* Implements the JainTcapProvider interface. The provider allows Listeners which
* implement the JainTcapListener interface to register with it as an event listener.
* Version 1.0d of the JainTcap RI is resticted to one Listener registration.
* A Listener can pass TCAP events in the form of ComponentReqEvents and DialogueReqEvents
* to the Provider. The Provider stores components in a hashtable indexed by its Dialogue Id.
* When a DialogueReqEvent is received it triggers the sending of stored components (if any) to
* registered Listener. The components associated with the dialogue are converted from Requests
* to Indications and stored in a simialr table as before. The Dialogue is then converted in a
* similar fashion and passed to the registered Listener. The conversion is via Converter.class.
* The Component indiaction are then passed to the Listener.
*
* @version 1.1
* @author AePONA
*/
public class PeerProvider implements JainTcapProvider {
public PeerProvider(){
System.out.println("PeerProvider : constructor");
Hashtable componentTable = new Hashtable();
Hashtable receivedComponentTable = new Hashtable();
}
/**
* Returns a unique dialogue id to initiate a dialogue with another TCAP user.
* @return the Dialogue Id returned by the underlying TCAP layer.
* @exception <var>IdNotAvailableException</var> if there are no more available Dialogue Ids
*/
public int getNewDialogueId( ) throws IdNotAvailableException {
System.out.println("PeerProvider : getNewDialogueId : getting a new DialogueId ");
/*
* Search the dialogueId table for the first available Dialogue Id
* or until there are no more available Dialogue Ids
* DialogueID start at one.
*/
currentDialogueId = MIN_DIALOGUE_ID;
while(currentDialogueId < MAX_DIALOGUE_IDS) {
if (dialogueIdTable.isEmpty()) {
System.out.println("PeerProvider : getNewDialogueId : Dialogue ID Table is empty.");
}
if (!dialogueIdTable.containsKey(new Integer(currentDialogueId))){
/*
* this Dialogue Id is not in use so create a new
* entry in the Dialogue Id table and return the
* newly allocated Diaogue Id
*/
dialogueIdTable.put(new Integer(currentDialogueId), new Vector());
System.out.println("PeerProvider : getNewDialogueId : Returning Current Did from Provider : " +currentDialogueId);
return(currentDialogueId);
}
currentDialogueId++;
}
// there is no avaliable dialogue ID so throw an Exception
throw new IdNotAvailableException("PeerProvider : getNewDialogueId : There are no free Dialogue Ids");
}
/**
* Release the dialogue Id back to the system.<br>
* <b>Note:</b> In some SS7 stacks the TCAP Dialogue Id is automatically
* released following the end of a TCAP transaction. In such instances the
* implementation of this method may be left null.
* @param <var>dialogueId</var> the Dialogue Id to be released
*/
public void releaseDialogueId(int dialogueId){
System.out.println("PeerProvider : releaseDialogueId : releasing DialogueId " +dialogueId );
dialogueIdTable.remove(new Integer(dialogueId));
}
/**
* Returns a unique Invoke Id for identifying invoke requests within
* the dialogue identified by the supplied Dialogue Id.
* Each dialogue between two <CODE>JainTcapListeners</CODE> is identified by
* a unique Dialogue Id. Note that the returned Invoke Id will be unique
* for a particular Dialogue Id.
* @param <var>dialogueId</var> the Dialogue Id for which an Invoke Id will be
* returned.
* @return a unique Invoke Id
* @exception <var>IdNotAvailableException</var> if there are no more available Invoke Ids
*/
public int getNewInvokeId(int dialogueId) throws IdNotAvailableException {
System.out.println("PeerProvider : getNewInvokeId : getting New Invoke ID : " +dialogueId);
Integer dIdInteger = new Integer(dialogueId);
if (dialogueIdTable.isEmpty()) {
System.out.println("PeerProvider : getNewInvokeId : dialogueIdTable is empty");
} else {
System.out.println("PeerProvider : getNewInvokeId : dialogueIdTable has entries");
}
if (!dialogueIdTable.containsKey(dIdInteger)){
throw new IdNotAvailableException("PeerProvider : getNewInvokeId : " +dialogueId +" is not in use");
} else {
/*
* found the Dialogue Id, now check for the first free Invoke Id
* by checking each invoke Id in turn
*/
Vector invokeIds = (Vector)dialogueIdTable.get(dIdInteger);
// InvokeID of zero not suuported by many SS7 Stacks
int currentInvokeId = MIN_INVOKE_ID;
while(currentInvokeId < MAX_INVOKE_IDS_PER_DIALOGUE){
System.out.println("PeerProvider : getNewInvoke : Checking if Invoke Id " +currentInvokeId +" is free");
if (!invokeIds.contains(new Integer(currentInvokeId))){
/*
* found the first free available Invoke Id
* now add it to the list of Invoke Ids used by
* this Dialogue and return its value
*/
invokeIds.addElement(new Integer(currentInvokeId));
System.out.println("PeerProvider : getNewInvokeId : returning currentInvoke Id");
return(currentInvokeId);
}
currentInvokeId++;
}
// there is no avaliable invoke ID so throw an Exception
throw new IdNotAvailableException("PeerProvider : getNewInvokeId : There are no free Invoke Ids for DialogueId (" +dialogueId +") ");
}
}
/**
* Releases the unique Invoke Id, allowing it to be reused within
* the dialogue identified by the supplied Dialogue Id.
* @param <var>invokeId</var> the Invoke Id to be released back into the system.
* @param <var>dialogueId</var> the Dialogue Id identifying the dialogue in
* which the invoke Id is used.
*/
public void releaseInvokeId(int invokeId, int dialogueId){
System.out.println("PeerProvider : releaseInvokeId : Attempting to release Invoke Id" +invokeId +" for Dialogue Id" +dialogueId);
Integer dIdIntObj = new Integer(dialogueId);
Integer invIdIntObj = new Integer(invokeId);
if(!dialogueIdTable.containsKey(dIdIntObj)){
System.out.println("PeerProvider : releaseInvokeId : The dialogue Id table does not contain Dialogue Id " + dialogueId);
} else {
Vector invIds = (Vector)dialogueIdTable.get(dIdIntObj);
if (invIds.contains(invIdIntObj)) {
invIds.removeElement(invIdIntObj);
System.out.println("PeerProvider : releaseInvokeId : The Invoke Id has been removed.");
} else {
System.out.println("PeerProvider : releaseInvokeId : The Invoke Id is not in use.");
}
}
}
/**
* Sends a Component Request primitive.
* @param <var>event</var> the Component Request event.
* @exception MandatoryParamsNotSetException thrown if all of the mandatory parameters
* required by this JainTcapProvider to send the Component Request are not set. <BR>
* Note that different implementations of this JainTcapProvider will mandate that
* different parameters must be set for each <CODE>ComponentReqEvent</CODE>.
* It is reccommended that the detail message returned in the
* <CODE>MandatoryParamsNotSetException</CODE> should be a <CODE>String</CODE> of the form:
* <P>
* <CENTER><B>"Parameter:<parameterName> not set"</B></CENTER>
*/
public void sendComponentReqEvent(ComponentReqEvent event) throws MandatoryParameterNotSetException {
/*
* The Reference Implementation checks for the Mandatory dialogue Id only
* An implementation should check for the all of the mandatory parameters that
* are required by that implementation
*/
try {
int did = event.getDialogueId();
} catch (MandatoryParameterNotSetException e) {
String errMsg = "PeerProvider : sendComponentReqEvent : Missing the Mandatory Dialogue Id";
System.out.println(errMsg);
throw new MandatoryParameterNotSetException(errMsg);
}
System.out.println(" The Event Type is " +event.getPrimitiveType());
String primName = CommonTools.getPrimitiveName(event.getPrimitiveType());
System.out.println("PeerProvider : sendComponentReqEvent : Received component of type" + CommonTools.getPrimitiveName(event.getPrimitiveType()));
HandleComponentReq handleComponentReq = new HandleComponentReq(event);
handleComponentReq.start();
}
/**
* Sends a Dialogue Request primitive. This will trigger the transmission to the
* destionation node of the Dialogue request primitive along with any asociated
* Component request primitives that have previously been passed to this Provider.
* Since the same Provider will be used to handle a particular
* transaction, Dialogue Request Events with the same Originating Transaction Id
* must be sent to the same Provider.
* @param <var>event</var> the Dialogue Request event to be sent into the stack.
* @exception MandatoryParamsNotSetException thrown if all of the mandatory parameters
* required by this JainTcapProvider to send the Dialogue Request are not set. <BR>
* Note that different implementations of this JainTcapProvider will mandate that
* different parameters must be set for each <CODE>DialogueReqEvent</CODE>.
* It is reccommended that the detail message returned in the
* <CODE>MandatoryParamsNotSetException</CODE> should be a <CODE>String</CODE> of the form:
* <P>
* <CENTER><B>"Parameter:<parameterName> not set"</B></CENTER>
*
*/
public void sendDialogueReqEvent(DialogueReqEvent event) throws MandatoryParameterNotSetException{
System.out.println("PeerProvider : sendDialogueReqEvent : Received dialogue of type : " + CommonTools.getPrimitiveName(event.getPrimitiveType()));
/*
* The Reference Implementation checks for the Mandatory dialogue Id only
* An implementation should check for the all of the mandatory parameters that
* are required by that implementation
*/
if (event.getPrimitiveType() == jain.protocol.ss7.tcap.TcapConstants.PRIMITIVE_UNIDIRECTIONAL){
//UNIDIRECTIONAL does not have a dialogue ID
} else {
try {
int did = event.getDialogueId();
} catch (MandatoryParameterNotSetException e) {
String errMsg = "PeerProvider : sendDialogueReqEvent : Missing mandatory Dialogue Id ";
System.out.println(errMsg);
throw new MandatoryParameterNotSetException(errMsg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -