
org.restcomm.protocols.ss7.inap.INAPStackImpl Maven / Gradle / Ivy
/*
* Mobius Software LTD
* Copyright 2019, Mobius Software LTD and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see
*/
package org.restcomm.protocols.ss7.inap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.restcomm.protocols.ss7.inap.api.INAPMessageType;
import org.restcomm.protocols.ss7.inap.api.INAPProvider;
import org.restcomm.protocols.ss7.inap.api.INAPStack;
import org.restcomm.protocols.ss7.inap.api.errors.INAPErrorCode;
import org.restcomm.protocols.ss7.sccp.SccpProvider;
import org.restcomm.protocols.ss7.tcap.TCAPStackImpl;
import org.restcomm.protocols.ss7.tcap.api.TCAPProvider;
import org.restcomm.protocols.ss7.tcap.api.TCAPStack;
/**
*
* @author yulian.oifa
*
*/
public class INAPStackImpl implements INAPStack {
public static final String PROTOCOL_NAME="inap";
protected TCAPStack tcapStack = null;
protected INAPProviderImpl inapProvider = null;
private State state = State.IDLE;
private final String name;
private ConcurrentHashMap messagesSentByType=new ConcurrentHashMap();
private ConcurrentHashMap messagesReceivedByType=new ConcurrentHashMap();
private ConcurrentHashMap errorsSentByType=new ConcurrentHashMap();
private ConcurrentHashMap errorsReceivedByType=new ConcurrentHashMap();
private ConcurrentHashMap dialogsSentByType=new ConcurrentHashMap();
private ConcurrentHashMap dialogsReceivedByType=new ConcurrentHashMap();
private ConcurrentHashMap> messagesSentByTypeAndNetwork=new ConcurrentHashMap>();
private ConcurrentHashMap> messagesReceivedByTypeAndNetwork=new ConcurrentHashMap>();
private ConcurrentHashMap> errorsSentByTypeAndNetwork=new ConcurrentHashMap>();
private ConcurrentHashMap> errorsReceivedByTypeAndNetwork=new ConcurrentHashMap>();
private ConcurrentHashMap> dialogsSentByTypeAndNetwork=new ConcurrentHashMap>();
private ConcurrentHashMap> dialogsReceivedByTypeAndNetwork=new ConcurrentHashMap>();
public static List allMessageTypes=new ArrayList();
static
{
for(INAPMessageType messageType:INAPMessageType.values())
allMessageTypes.add(messageType.name());
allMessageTypes.add("unknown");
}
public INAPStackImpl(String name, SccpProvider sccpPprovider, int ssn,int threads) {
this.name = name;
this.tcapStack = new TCAPStackImpl(name, sccpPprovider, ssn, threads);
TCAPProvider tcapProvider = tcapStack.getProvider();
inapProvider = new INAPProviderImpl(name, this, tcapProvider);
this.state = State.CONFIGURED;
initCounters();
}
public INAPStackImpl(String name, TCAPProvider tcapProvider) {
this.name = name;
inapProvider = new INAPProviderImpl(name, this, tcapProvider);
this.tcapStack = tcapProvider.getStack();
this.state = State.CONFIGURED;
initCounters();
}
private void initCounters() {
for(String currName:INAPServiceBaseImpl.getNames()) {
dialogsSentByType.put(currName,new AtomicLong(0));
dialogsReceivedByType.put(currName,new AtomicLong(0));
}
for(INAPMessageType currType:INAPMessageType.values()) {
messagesSentByType.put(currType.name(),new AtomicLong(0));
messagesReceivedByType.put(currType.name(),new AtomicLong(0));
}
messagesSentByType.put("unknown",new AtomicLong(0));
messagesReceivedByType.put("unknown",new AtomicLong(0));
for(String currName:INAPErrorCode.getAllNames()) {
errorsSentByType.put(currName,new AtomicLong(0));
errorsReceivedByType.put(currName,new AtomicLong(0));
}
}
@Override
public String getName() {
return name;
}
@Override
public INAPProvider getProvider() {
return this.inapProvider;
}
@Override
public void start() throws Exception {
if (state != State.CONFIGURED) {
throw new IllegalStateException("Stack has not been configured or is already running!");
}
if (tcapStack != null) {
// this is null in junits!
this.tcapStack.start();
}
this.inapProvider.start();
this.state = State.RUNNING;
}
@Override
public void stop() {
if (state != State.RUNNING) {
throw new IllegalStateException("Stack is not running!");
}
this.inapProvider.stop();
if (tcapStack != null) {
this.tcapStack.stop();
}
this.state = State.CONFIGURED;
}
@Override
public TCAPStack getTCAPStack() {
return this.tcapStack;
}
private enum State {
IDLE, CONFIGURED, RUNNING;
}
@Override
public Map getMessagesSentByType() {
Map result=new HashMap();
Iterator> iterator=messagesSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getMessagesReceivedByType() {
Map result=new HashMap();
Iterator> iterator=messagesReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getErrorsSentByType() {
Map result=new HashMap();
Iterator> iterator=errorsSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getErrorsReceivedByType() {
Map result=new HashMap();
Iterator> iterator=errorsReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getDialogsSentByType() {
Map result=new HashMap();
Iterator> iterator=dialogsSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getDialogsReceivedByType() {
Map result=new HashMap();
Iterator> iterator=dialogsReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
return result;
}
@Override
public Map getMessagesSentByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map messagesSentByType = messagesSentByTypeAndNetwork.get(networkID);
if(messagesSentByType!=null) {
Iterator> iterator=messagesSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
@Override
public Map getMessagesReceivedByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map messagesReceivedByType = messagesReceivedByTypeAndNetwork.get(networkID);
if(messagesReceivedByType!=null) {
Iterator> iterator=messagesReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
@Override
public Map getErrorsSentByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map errorsSentByType = errorsSentByTypeAndNetwork.get(networkID);
if(errorsSentByType!=null) {
Iterator> iterator=errorsSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
@Override
public Map getErrorsReceivedByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map errorsReceivedByType = errorsReceivedByTypeAndNetwork.get(networkID);
if(errorsReceivedByType!=null) {
Iterator> iterator=errorsReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
@Override
public Map getDialogsSentByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map dialogsSentByType = dialogsSentByTypeAndNetwork.get(networkID);
if(dialogsSentByType!=null) {
Iterator> iterator=dialogsSentByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
@Override
public Map getDialogsReceivedByTypeAndNetwork(int networkID) {
Map result=new HashMap();
Map dialogsReceivedByType = dialogsReceivedByTypeAndNetwork.get(networkID);
if(dialogsReceivedByType!=null) {
Iterator> iterator=dialogsReceivedByType.entrySet().iterator();
while(iterator.hasNext()) {
Entry currEntry=iterator.next();
result.put(currEntry.getKey(), currEntry.getValue().get());
}
}
return result;
}
public void newMessageReceived(String messageType,int networkID) {
messagesSentByType.get(messageType).incrementAndGet();
ConcurrentHashMap messagesSentByType =messagesSentByTypeAndNetwork.get(networkID);
if(messagesSentByType==null) {
messagesSentByType=new ConcurrentHashMap();
for(INAPMessageType currType:INAPMessageType.values())
messagesSentByType.put(currType.name(),new AtomicLong(0));
messagesSentByType.put("unknown",new AtomicLong(0));
ConcurrentHashMap oldValue=messagesSentByTypeAndNetwork.putIfAbsent(networkID, messagesSentByType);
if(oldValue!=null)
messagesSentByType=oldValue;
}
messagesSentByType.get(messageType).incrementAndGet();
}
public void newMessageSent(String messageType,int networkID) {
messagesReceivedByType.get(messageType).incrementAndGet();
ConcurrentHashMap messagesReceivedByType =messagesReceivedByTypeAndNetwork.get(networkID);
if(messagesReceivedByType==null) {
messagesReceivedByType=new ConcurrentHashMap();
for(INAPMessageType currType:INAPMessageType.values())
messagesReceivedByType.put(currType.name(),new AtomicLong(0));
messagesReceivedByType.put("unknown",new AtomicLong(0));
ConcurrentHashMap oldValue=messagesReceivedByTypeAndNetwork.putIfAbsent(networkID, messagesReceivedByType);
if(oldValue!=null)
messagesReceivedByType=oldValue;
}
messagesReceivedByType.get(messageType).incrementAndGet();
}
public void newErrorReceived(String errorType,int networkID) {
errorsSentByType.get(errorType).incrementAndGet();
ConcurrentHashMap errorsSentByType =errorsSentByTypeAndNetwork.get(networkID);
if(errorsSentByType==null) {
errorsSentByType=new ConcurrentHashMap();
for(String currName:INAPErrorCode.getAllNames())
errorsSentByType.put(currName,new AtomicLong(0));
ConcurrentHashMap oldValue=errorsSentByTypeAndNetwork.putIfAbsent(networkID, errorsSentByType);
if(oldValue!=null)
errorsSentByType=oldValue;
}
errorsSentByType.get(errorType).incrementAndGet();
}
public void newErrorSent(String errorType,int networkID) {
errorsReceivedByType.get(errorType).incrementAndGet();
ConcurrentHashMap errorsReceivedByType =errorsReceivedByTypeAndNetwork.get(networkID);
if(errorsReceivedByType==null) {
errorsReceivedByType=new ConcurrentHashMap();
for(String currName:INAPErrorCode.getAllNames())
errorsReceivedByType.put(currName,new AtomicLong(0));
ConcurrentHashMap oldValue=errorsReceivedByTypeAndNetwork.putIfAbsent(networkID, errorsReceivedByType);
if(oldValue!=null)
errorsReceivedByType=oldValue;
}
errorsReceivedByType.get(errorType).incrementAndGet();
}
public void newDialogReceived(String dialogType,int networkID) {
dialogsSentByType.get(dialogType).incrementAndGet();
ConcurrentHashMap dialogsSentByType =dialogsSentByTypeAndNetwork.get(networkID);
if(dialogsSentByType==null) {
dialogsSentByType=new ConcurrentHashMap();
for(String currName:INAPServiceBaseImpl.getNames())
dialogsSentByType.put(currName,new AtomicLong(0));
ConcurrentHashMap oldValue=dialogsSentByTypeAndNetwork.putIfAbsent(networkID, dialogsSentByType);
if(oldValue!=null)
dialogsSentByType=oldValue;
}
dialogsSentByType.get(dialogType).incrementAndGet();
}
public void newDialogSent(String dialogType,int networkID) {
dialogsReceivedByType.get(dialogType).incrementAndGet();
ConcurrentHashMap dialogsReceivedByType =dialogsReceivedByTypeAndNetwork.get(networkID);
if(dialogsReceivedByType==null) {
dialogsReceivedByType=new ConcurrentHashMap();
for(String currName:INAPServiceBaseImpl.getNames())
dialogsReceivedByType.put(currName,new AtomicLong(0));
ConcurrentHashMap oldValue=dialogsReceivedByTypeAndNetwork.putIfAbsent(networkID, dialogsReceivedByType);
if(oldValue!=null)
dialogsReceivedByType=oldValue;
}
dialogsReceivedByType.get(dialogType).incrementAndGet();
}
@Override
public String getProtocol() {
return PROTOCOL_NAME;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy