Skip to content

Commit 9857062

Browse files
author
Ievgenii Vdovenko
committed
#66 added configurable timeouts for CAP/MAP stacks
1 parent c4738fc commit 9857062

File tree

21 files changed

+521
-111
lines changed

21 files changed

+521
-111
lines changed

cap/cap-api/src/main/java/org/restcomm/protocols/ss7/cap/api/CAPDialog.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
*/
4343
public interface CAPDialog extends Serializable {
4444

45-
// Invoke timers
46-
int _Timer_CircuitSwitchedCallControl_Short = 6000; // 1 - 10 sec
47-
int _Timer_CircuitSwitchedCallControl_Medium = 30000; // 1 - 60 sec
48-
int _Timer_CircuitSwitchedCallControl_Long = 300000; // 1 s - 30 minutes
49-
int _Timer_Sms_Short = 10000; // 1 - 20 sec
50-
int _Timer_Gprs_Short = 10000; // 1 - 20 sec
51-
5245
int _Timer_Default = -1;
5346

47+
// Invoke timers
48+
int getTimerCircuitSwitchedCallControlShort();
49+
int getTimerCircuitSwitchedCallControlMedium();
50+
int getTimerCircuitSwitchedCallControlLong();
51+
int getTimerSmsShort();
52+
int getTimerGprsShort();
53+
5454
/*
5555
* Setting this property to true lead that all sent to TCAP messages of this Dialog will be marked as "ReturnMessageOnError"
5656
* (SCCP will return the notification is the message has non been delivered to the peer)

cap/cap-impl/src/main/java/org/restcomm/protocols/ss7/cap/CAPDialogImpl.java

+27
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ public abstract class CAPDialogImpl implements CAPDialog {
7979
boolean returnMessageOnError = false;
8080
protected MessageType tcapMessageType;
8181
protected DelayedAreaState delayedAreaState;
82+
private CAPStackConfigurationManagement capStackConfigurationManagement;
8283

8384
protected CAPDialogImpl(CAPApplicationContext appCntx, Dialog tcapDialog, CAPProviderImpl capProviderImpl,
8485
CAPServiceBase capService) {
8586
this.appCntx = appCntx;
8687
this.tcapDialog = tcapDialog;
8788
this.capProviderImpl = capProviderImpl;
8889
this.capService = capService;
90+
this.capStackConfigurationManagement = CAPStackConfigurationManagement.getInstance();
8991
}
9092

9193
public SccpAddress getLocalAddress() {
@@ -625,4 +627,29 @@ public long getIdleTaskTimeout() {
625627
public void setIdleTaskTimeout(long idleTaskTimeoutMs) {
626628
tcapDialog.setIdleTaskTimeout(idleTaskTimeoutMs);
627629
}
630+
631+
@Override
632+
public int getTimerCircuitSwitchedCallControlShort() {
633+
return capStackConfigurationManagement.getTimerCircuitSwitchedCallControlShort();
634+
}
635+
636+
@Override
637+
public int getTimerCircuitSwitchedCallControlMedium() {
638+
return capStackConfigurationManagement.getTimerCircuitSwitchedCallControlMedium();
639+
}
640+
641+
@Override
642+
public int getTimerCircuitSwitchedCallControlLong() {
643+
return capStackConfigurationManagement.getTimerCircuitSwitchedCallControlLong();
644+
}
645+
646+
@Override
647+
public int getTimerSmsShort() {
648+
return capStackConfigurationManagement.getTimerSmsShort();
649+
}
650+
651+
@Override
652+
public int getTimerGprsShort() {
653+
return capStackConfigurationManagement.getTimerGprsShort();
654+
}
628655
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package org.restcomm.protocols.ss7.cap;
2+
3+
import javolution.text.TextBuilder;
4+
import javolution.xml.XMLBinding;
5+
import javolution.xml.XMLObjectReader;
6+
import javolution.xml.XMLObjectWriter;
7+
import javolution.xml.stream.XMLStreamException;
8+
9+
import java.io.File;
10+
import java.io.FileInputStream;
11+
import java.io.FileNotFoundException;
12+
import java.io.FileOutputStream;
13+
14+
public class CAPStackConfigurationManagement {
15+
private static final String PERSIST_FILE_NAME = "management.xml";
16+
private static final String CAP_MANAGEMENT_PERSIST_DIR_KEY = "capmanagement.persist.dir";
17+
private static final String USER_DIR_KEY = "user.dir";
18+
private static final String TAB_INDENT = "\t";
19+
private static final String DEFAULT_CONFIG_FILE_NAME = "CapStack";
20+
21+
private static final String TIMER_CIRCUITSWITCHEDCALLCONTROL_SHORT = "timercircuitswitchedcallcontrolshort";
22+
private static final String TIMER_CIRCUITSWITCHEDCALLCONTROL_MEDIUM = "timercircuitswitchedcallcontrolmedium";
23+
private static final String TIMER_CIRCUITSWITCHEDCALLCONTROL_LONG = "timercircuitswitchedcallcontrollong";
24+
private static final String TIMER_SMS_SHORT = "timersmsshort";
25+
private static final String TIMER_GPRS_SHORT = "timergprsshort";
26+
27+
private static final XMLBinding binding = new XMLBinding();
28+
private static CAPStackConfigurationManagement instance = new CAPStackConfigurationManagement();
29+
30+
private final TextBuilder persistFile = TextBuilder.newInstance();
31+
private String configFileName = DEFAULT_CONFIG_FILE_NAME;
32+
private String persistDir = null;
33+
34+
private int _Timer_CircuitSwitchedCallControl_Short = 6000; // 1 - 10 sec
35+
private int _Timer_CircuitSwitchedCallControl_Medium = 30000; // 1 - 60 sec
36+
private int _Timer_CircuitSwitchedCallControl_Long = 300000; // 1 s - 30 minutes
37+
private int _Timer_Sms_Short = 10000; // 1 - 20 sec
38+
private int _Timer_Gprs_Short = 10000; // 1 - 20 sec
39+
40+
private CAPStackConfigurationManagement() {
41+
}
42+
43+
public static CAPStackConfigurationManagement getInstance() {
44+
return instance;
45+
}
46+
47+
public void setPersistDir(String persistDir) {
48+
this.persistDir = persistDir;
49+
this.setPersistFile();
50+
}
51+
52+
private void setPersistFile() {
53+
this.persistFile.clear();
54+
55+
if (persistDir != null) {
56+
this.persistFile.append(persistDir).append(File.separator).append(this.configFileName).append("_").append(PERSIST_FILE_NAME);
57+
} else {
58+
persistFile.append(System.getProperty(CAP_MANAGEMENT_PERSIST_DIR_KEY, System.getProperty(USER_DIR_KEY))).append(File.separator).append(this.configFileName)
59+
.append("_").append(PERSIST_FILE_NAME);
60+
}
61+
}
62+
63+
/**
64+
* Persist
65+
*/
66+
public void store() {
67+
// TODO : Should we keep reference to Objects rather than recreating
68+
// everytime?
69+
try {
70+
XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream(persistFile.toString()));
71+
72+
writer.setBinding(binding);
73+
writer.setIndentation(TAB_INDENT);
74+
75+
writer.write(this._Timer_CircuitSwitchedCallControl_Short, TIMER_CIRCUITSWITCHEDCALLCONTROL_SHORT, Integer.class);
76+
writer.write(this._Timer_CircuitSwitchedCallControl_Medium, TIMER_CIRCUITSWITCHEDCALLCONTROL_MEDIUM, Integer.class);
77+
writer.write(this._Timer_CircuitSwitchedCallControl_Long, TIMER_CIRCUITSWITCHEDCALLCONTROL_LONG, Integer.class);
78+
writer.write(this._Timer_Sms_Short, TIMER_SMS_SHORT, Integer.class);
79+
writer.write(this._Timer_Gprs_Short, TIMER_GPRS_SHORT, Integer.class);
80+
81+
writer.close();
82+
} catch (Exception e) {
83+
System.err.println(String.format("Error while persisting the CAP Resource state in file=%s", persistFile.toString()));
84+
e.printStackTrace();
85+
}
86+
}
87+
88+
/**
89+
* Load and create LinkSets and Link from persisted file
90+
* <p>
91+
* load() is called from CAPStackImpl
92+
*/
93+
public void load() {
94+
try {
95+
setPersistFile();
96+
XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream(persistFile.toString()));
97+
reader.setBinding(binding);
98+
load(reader);
99+
} catch (XMLStreamException | FileNotFoundException e) {
100+
System.err.println(String.format("Error while load the CAP Resource state from file=%s", persistFile.toString()));
101+
e.printStackTrace();
102+
}
103+
}
104+
105+
private void load(XMLObjectReader reader) throws XMLStreamException {
106+
Integer val = reader.read(TIMER_CIRCUITSWITCHEDCALLCONTROL_SHORT, Integer.class);
107+
if (val != null)
108+
this._Timer_CircuitSwitchedCallControl_Short = val;
109+
110+
val = reader.read(TIMER_CIRCUITSWITCHEDCALLCONTROL_MEDIUM, Integer.class);
111+
if (val != null)
112+
this._Timer_CircuitSwitchedCallControl_Medium = val;
113+
114+
val = reader.read(TIMER_CIRCUITSWITCHEDCALLCONTROL_LONG, Integer.class);
115+
if (val != null)
116+
this._Timer_CircuitSwitchedCallControl_Long = val;
117+
118+
val = reader.read(TIMER_SMS_SHORT, Integer.class);
119+
if (val != null)
120+
this._Timer_Sms_Short = val;
121+
122+
val = reader.read(TIMER_GPRS_SHORT, Integer.class);
123+
if (val != null)
124+
this._Timer_Gprs_Short = val;
125+
126+
reader.close();
127+
}
128+
129+
public void setConfigFileName(String configFileName) {
130+
this.configFileName = configFileName;
131+
}
132+
133+
public int getTimerCircuitSwitchedCallControlShort() {
134+
return _Timer_CircuitSwitchedCallControl_Short;
135+
}
136+
137+
public int getTimerCircuitSwitchedCallControlMedium() {
138+
return _Timer_CircuitSwitchedCallControl_Medium;
139+
}
140+
141+
public int getTimerCircuitSwitchedCallControlLong() {
142+
return _Timer_CircuitSwitchedCallControl_Long;
143+
}
144+
145+
public int getTimerSmsShort() {
146+
return _Timer_Sms_Short;
147+
}
148+
149+
public int getTimerGprsShort() {
150+
return _Timer_Gprs_Short;
151+
}
152+
153+
public void set_Timer_CircuitSwitchedCallControl_Short(int _Timer_CircuitSwitchedCallControl_Short) {
154+
this._Timer_CircuitSwitchedCallControl_Short = _Timer_CircuitSwitchedCallControl_Short;
155+
this.store();
156+
}
157+
158+
public void set_Timer_CircuitSwitchedCallControl_Medium(int _Timer_CircuitSwitchedCallControl_Medium) {
159+
this._Timer_CircuitSwitchedCallControl_Medium = _Timer_CircuitSwitchedCallControl_Medium;
160+
this.store();
161+
}
162+
163+
public void set_Timer_CircuitSwitchedCallControl_Long(int _Timer_CircuitSwitchedCallControl_Long) {
164+
this._Timer_CircuitSwitchedCallControl_Long = _Timer_CircuitSwitchedCallControl_Long;
165+
this.store();
166+
}
167+
168+
public void set_Timer_Sms_Short(int _Timer_Sms_Short) {
169+
this._Timer_Sms_Short = _Timer_Sms_Short;
170+
this.store();
171+
}
172+
173+
public void set_Timer_Gprs_Short(int _Timer_Gprs_Short) {
174+
this._Timer_Gprs_Short = _Timer_Gprs_Short;
175+
this.store();
176+
}
177+
}

cap/cap-impl/src/main/java/org/restcomm/protocols/ss7/cap/CAPStackImpl.java

+18
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,30 @@ public class CAPStackImpl implements CAPStack {
4444

4545
private final String name;
4646

47+
private CAPStackConfigurationManagement capStackCfgManagement;
48+
49+
private String persistDir = null;
50+
4751
public CAPStackImpl(String name, SccpProvider sccpPprovider, int ssn) {
4852
this.name = name;
4953
this.tcapStack = new TCAPStackImpl(name, sccpPprovider, ssn);
5054
TCAPProvider tcapProvider = tcapStack.getProvider();
5155
capProvider = new CAPProviderImpl(name, tcapProvider);
5256

5357
this.state = State.CONFIGURED;
58+
59+
this.capStackCfgManagement = CAPStackConfigurationManagement.getInstance();
60+
this.capStackCfgManagement.setConfigFileName(this.name);
5461
}
5562

5663
public CAPStackImpl(String name, TCAPProvider tcapProvider) {
5764
this.name = name;
5865
capProvider = new CAPProviderImpl(name, tcapProvider);
5966
this.tcapStack = tcapProvider.getStack();
6067
this.state = State.CONFIGURED;
68+
69+
this.capStackCfgManagement = CAPStackConfigurationManagement.getInstance();
70+
this.capStackCfgManagement.setConfigFileName(this.name);
6171
}
6272

6373
@Override
@@ -72,6 +82,9 @@ public CAPProvider getCAPProvider() {
7282

7383
@Override
7484
public void start() throws Exception {
85+
this.capStackCfgManagement.setPersistDir(this.persistDir);
86+
this.capStackCfgManagement.load();
87+
7588
if (state != State.CONFIGURED) {
7689
throw new IllegalStateException("Stack has not been configured or is already running!");
7790
}
@@ -96,13 +109,18 @@ public void stop() {
96109
}
97110

98111
this.state = State.CONFIGURED;
112+
this.capStackCfgManagement.store();
99113
}
100114

101115
@Override
102116
public TCAPStack getTCAPStack() {
103117
return this.tcapStack;
104118
}
105119

120+
public void setPersistDir(String persistDir) {
121+
this.persistDir = persistDir;
122+
}
123+
106124
private enum State {
107125
IDLE, CONFIGURED, RUNNING;
108126
}

0 commit comments

Comments
 (0)