PageRenderTime 42ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/isup/isup-impl/src/main/java/org/mobicents/protocols/ss7/isup/impl/Circuit.java

http://mobicents.googlecode.com/
Java | 1409 lines | 886 code | 193 blank | 330 comment | 74 complexity | 30784c4b82bfeceed5ef35fcf7258b93 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.ss7.isup.impl;
  23. import java.io.ByteArrayOutputStream;
  24. import java.io.IOException;
  25. import java.util.List;
  26. import java.util.concurrent.Future;
  27. import java.util.concurrent.ScheduledExecutorService;
  28. import java.util.concurrent.TimeUnit;
  29. import javolution.util.FastList;
  30. import javolution.util.ReentrantLock;
  31. import org.mobicents.protocols.ss7.isup.ISUPEvent;
  32. import org.mobicents.protocols.ss7.isup.ISUPTimeoutEvent;
  33. import org.mobicents.protocols.ss7.isup.ParameterException;
  34. import org.mobicents.protocols.ss7.isup.impl.message.AbstractISUPMessage;
  35. import org.mobicents.protocols.ss7.isup.message.AddressCompleteMessage;
  36. import org.mobicents.protocols.ss7.isup.message.BlockingAckMessage;
  37. import org.mobicents.protocols.ss7.isup.message.BlockingMessage;
  38. import org.mobicents.protocols.ss7.isup.message.CircuitGroupBlockingMessage;
  39. import org.mobicents.protocols.ss7.isup.message.CircuitGroupQueryMessage;
  40. import org.mobicents.protocols.ss7.isup.message.CircuitGroupQueryResponseMessage;
  41. import org.mobicents.protocols.ss7.isup.message.CircuitGroupResetAckMessage;
  42. import org.mobicents.protocols.ss7.isup.message.CircuitGroupResetMessage;
  43. import org.mobicents.protocols.ss7.isup.message.CircuitGroupUnblockingAckMessage;
  44. import org.mobicents.protocols.ss7.isup.message.CircuitGroupUnblockingMessage;
  45. import org.mobicents.protocols.ss7.isup.message.ConnectMessage;
  46. import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
  47. import org.mobicents.protocols.ss7.isup.message.InformationMessage;
  48. import org.mobicents.protocols.ss7.isup.message.InformationRequestMessage;
  49. import org.mobicents.protocols.ss7.isup.message.InitialAddressMessage;
  50. import org.mobicents.protocols.ss7.isup.message.ReleaseCompleteMessage;
  51. import org.mobicents.protocols.ss7.isup.message.ReleaseMessage;
  52. import org.mobicents.protocols.ss7.isup.message.ResetCircuitMessage;
  53. import org.mobicents.protocols.ss7.isup.message.SubsequentAddressMessage;
  54. import org.mobicents.protocols.ss7.isup.message.UnblockingAckMessage;
  55. import org.mobicents.protocols.ss7.isup.message.UnblockingMessage;
  56. import org.mobicents.protocols.ss7.isup.message.parameter.CauseIndicators;
  57. import org.mobicents.protocols.ss7.mtp.Mtp3;
  58. import org.mobicents.protocols.ss7.mtp.Mtp3TransferPrimitive;
  59. /**
  60. *
  61. * @author baranowb
  62. *
  63. */
  64. @SuppressWarnings("rawtypes")
  65. class Circuit implements Runnable {
  66. private final int cic;
  67. private final int dpc;
  68. private final ISUPProviderImpl provider;
  69. private ReentrantLock lock = new ReentrantLock();
  70. private ScheduledExecutorService executor;
  71. private List<ISUPMessage> incoming = new FastList<ISUPMessage>(); // use
  72. // linked
  73. // list
  74. // ?
  75. private ByteArrayOutputStream bos = new ByteArrayOutputStream(300);
  76. /**
  77. * @param cic
  78. */
  79. public Circuit(int cic, int dpc,ISUPProviderImpl provider) {
  80. this.cic = cic;
  81. this.dpc = dpc;
  82. this.provider = provider;
  83. this.executor = provider.getExecutor(cic);
  84. }
  85. /**
  86. * @param timerId
  87. * @return
  88. */
  89. public boolean cancelTimer(int timerId) {
  90. try {
  91. lock.lock();
  92. switch (timerId) {
  93. case ISUPTimeoutEvent.T1:
  94. return cancelT1();
  95. case ISUPTimeoutEvent.T5:
  96. return cancelT5();
  97. case ISUPTimeoutEvent.T7:
  98. return cancelT7();
  99. case ISUPTimeoutEvent.T12:
  100. return cancelT12();
  101. case ISUPTimeoutEvent.T13:
  102. return cancelT13();
  103. case ISUPTimeoutEvent.T14:
  104. return cancelT14();
  105. case ISUPTimeoutEvent.T15:
  106. return cancelT15();
  107. case ISUPTimeoutEvent.T16:
  108. return cancelT16();
  109. case ISUPTimeoutEvent.T17:
  110. return cancelT17();
  111. case ISUPTimeoutEvent.T18:
  112. return cancelT18();
  113. case ISUPTimeoutEvent.T19:
  114. return cancelT19();
  115. case ISUPTimeoutEvent.T20:
  116. return cancelT20();
  117. case ISUPTimeoutEvent.T21:
  118. return cancelT21();
  119. case ISUPTimeoutEvent.T22:
  120. return cancelT22();
  121. case ISUPTimeoutEvent.T23:
  122. return cancelT23();
  123. case ISUPTimeoutEvent.T28:
  124. return cancelT28();
  125. case ISUPTimeoutEvent.T33:
  126. return cancelT33();
  127. default:
  128. return false;
  129. }
  130. } finally {
  131. lock.unlock();
  132. }
  133. }
  134. /**
  135. * @param message
  136. */
  137. public void receive(ISUPMessage message) {
  138. incoming.add(message);
  139. this.executor.execute(this);
  140. }
  141. /**
  142. * @param message
  143. * @throws ParameterException
  144. * @throws IOException
  145. */
  146. public void send(ISUPMessage message) throws ParameterException, IOException {
  147. try {
  148. lock.lock();
  149. bos.reset();
  150. // FIXME: add SEG creation?
  151. Mtp3TransferPrimitive msg = decorate(message);
  152. // process timers
  153. switch (message.getMessageType().getCode()) {
  154. case ReleaseMessage.MESSAGE_CODE:
  155. startRELTimers(msg, (ReleaseMessage) message);
  156. break;
  157. case SubsequentAddressMessage.MESSAGE_CODE:
  158. case InitialAddressMessage.MESSAGE_CODE:
  159. startXAMTimers(message);
  160. break;
  161. case BlockingMessage.MESSAGE_CODE:
  162. startBLOTimers(msg, (BlockingMessage) message);
  163. break;
  164. case UnblockingMessage.MESSAGE_CODE:
  165. startUBLTimers(msg, (UnblockingMessage) message);
  166. break;
  167. case ResetCircuitMessage.MESSAGE_CODE:
  168. startRSCTimers(msg, (ResetCircuitMessage) message);
  169. break;
  170. case CircuitGroupBlockingMessage.MESSAGE_CODE:
  171. startCGBTimers(msg, (CircuitGroupBlockingMessage) message);
  172. break;
  173. case CircuitGroupUnblockingMessage.MESSAGE_CODE:
  174. startCGUTimers(msg, (CircuitGroupUnblockingMessage) message);
  175. break;
  176. case CircuitGroupResetMessage.MESSAGE_CODE:
  177. startGRSTimers(msg, (CircuitGroupResetMessage) message);
  178. break;
  179. case CircuitGroupQueryMessage.MESSAGE_CODE:
  180. startCQMTimers((CircuitGroupQueryMessage) message);
  181. break;
  182. case InformationRequestMessage.MESSAGE_CODE:
  183. startINRTimers((InformationRequestMessage) message);
  184. break;
  185. }
  186. // send
  187. provider.send(msg);
  188. } finally {
  189. lock.unlock();
  190. }
  191. }
  192. /**
  193. * @param message
  194. * @return
  195. * @throws ParameterException
  196. * @throws IOException
  197. */
  198. private Mtp3TransferPrimitive decorate(ISUPMessage message) throws ParameterException, IOException {
  199. ((AbstractISUPMessage) message).encode(bos);
  200. byte[] encoded = bos.toByteArray();
  201. int opc = this.provider.getLocalSpc();
  202. int dpc = this.dpc;
  203. int si = Mtp3._SI_SERVICE_ISUP;
  204. int ni = this.provider.getNi();
  205. int sls = message.getSls() & 0x0F; //promote
  206. // int ssi = ni << 2;
  207. // ByteArrayOutputStream bout = new ByteArrayOutputStream();
  208. // // encoding routing label
  209. // bout.write((byte) (((ssi & 0x0F) << 4) | (si & 0x0F)));
  210. // bout.write((byte) dpc);
  211. // bout.write((byte) (((dpc >> 8) & 0x3F) | ((opc & 0x03) << 6)));
  212. // bout.write((byte) (opc >> 2));
  213. // bout.write((byte) (((opc >> 10) & 0x0F) | ((sls & 0x0F) << 4)));
  214. // bout.write(encoded);
  215. // byte[] msg = bout.toByteArray();
  216. Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive(si, ni, 0, opc, dpc, sls, encoded);
  217. return msg;
  218. }
  219. public void run() {
  220. try {
  221. lock.lock();
  222. ISUPMessage message = this.incoming.remove(0);
  223. // process timers
  224. switch (message.getMessageType().getCode()) {
  225. // FIXME: add check for SEG
  226. case ReleaseCompleteMessage.MESSAGE_CODE:
  227. // this is tricy BS.... its REL and RSC are answered with RLC
  228. if (!stopRELTimers()) {
  229. stopRSCTimers();
  230. }
  231. break;
  232. case AddressCompleteMessage.MESSAGE_CODE:
  233. case ConnectMessage.MESSAGE_CODE:
  234. stoptXAMTimers();
  235. break;
  236. case BlockingAckMessage.MESSAGE_CODE:
  237. stoptBLOTimers();
  238. break;
  239. case UnblockingAckMessage.MESSAGE_CODE:
  240. stoptUBLTimers();
  241. break;
  242. case CircuitGroupBlockingMessage.MESSAGE_CODE:
  243. stoptCGBTimers();
  244. break;
  245. case CircuitGroupUnblockingAckMessage.MESSAGE_CODE:
  246. stoptCGUTimers();
  247. break;
  248. case CircuitGroupResetAckMessage.MESSAGE_CODE:
  249. stoptGRSTimers();
  250. break;
  251. case CircuitGroupQueryResponseMessage.MESSAGE_CODE:
  252. stoptCQMTimers();
  253. break;
  254. case InformationMessage.MESSAGE_CODE:
  255. stoptINRTimers();
  256. break;
  257. }
  258. // deliver
  259. ISUPEvent event = new ISUPEvent(provider, message);
  260. this.provider.deliver(event);
  261. } catch (Exception e) {
  262. // catch exception, so thread dont die.
  263. e.printStackTrace();
  264. } finally {
  265. lock.unlock();
  266. }
  267. }
  268. // ----------------- timer handlers ----------------------
  269. // FIXME: check how t3 works....
  270. private Future t1;
  271. private Future t5;
  272. private Mtp3TransferPrimitive t1t5encodedREL; // keep encoded value, so we can simply send,
  273. // without spending CPU on encoding.
  274. private ReleaseMessage t1t5REL; // keep for timers.
  275. private Future t7;
  276. private ISUPMessage t7AddressMessage; // IAM/SAM
  277. // FIXME: t8 - receive IAM with contuuity check ind.
  278. // FIXME: t11
  279. // FIXME: t11
  280. private Future t12;
  281. private Future t13;
  282. private Mtp3TransferPrimitive t12t13encodedBLO; // keep encoded value, so we can simply
  283. // send, without spending CPU on
  284. // encoding.
  285. private BlockingMessage t12t13BLO; // keep for timers.
  286. private Future t14;
  287. private Future t15;
  288. private Mtp3TransferPrimitive t14t15encodedUBL; // keep encoded value, so we can simply
  289. // send, without spending CPU on
  290. // encoding.
  291. private UnblockingMessage t14t15UBL; // keep for timers.
  292. private Future t16;
  293. private Future t17;
  294. private Mtp3TransferPrimitive t16t17encodedRSC; // keep encoded value, so we can simply
  295. // send, without spending CPU on
  296. // encoding.
  297. private ResetCircuitMessage t16t17RSC; // keep for timers.
  298. private Future t18;
  299. private Future t19;
  300. private Mtp3TransferPrimitive t18t19encodedCGB; // keep encoded value, so we can simply
  301. // send, without spending CPU on
  302. // encoding.
  303. private CircuitGroupBlockingMessage t18t19CGB; // keep for timers.
  304. private Future t20;
  305. private Future t21;
  306. private Mtp3TransferPrimitive t20t21encodedCGU; // keep encoded value, so we can simply
  307. // send, without spending CPU on
  308. // encoding.
  309. private CircuitGroupUnblockingMessage t20t21CGU; // keep for timers.
  310. private Future t22;
  311. private Future t23;
  312. private Mtp3TransferPrimitive t22t23encodedGRS; // keep encoded value, so we can simply
  313. // send, without spending CPU on
  314. // encoding.
  315. private CircuitGroupResetMessage t22t23GRS; // keep for timers.
  316. private Future t28;
  317. private CircuitGroupQueryMessage t28CQM;
  318. private Future t33;
  319. private InformationRequestMessage t33INR;
  320. // FIXME: t34 - check how SEG works
  321. private void startRELTimers(Mtp3TransferPrimitive encoded, ReleaseMessage rel) {
  322. // FIXME: add lock ?
  323. this.t1t5encodedREL = encoded;
  324. this.t1t5REL = rel;
  325. // it is started always.
  326. startT1();
  327. if (t5 == null) {
  328. startT5();
  329. }
  330. }
  331. /**
  332. * @return
  333. */
  334. private boolean stopRELTimers() {
  335. if (this.t1 != null || this.t5 != null) {
  336. cancelT1();
  337. cancelT5();
  338. return true;
  339. } else {
  340. return false;
  341. }
  342. }
  343. /**
  344. * @param encoded
  345. * @param message
  346. */
  347. private void startXAMTimers(ISUPMessage message) {
  348. this.cancelT7();
  349. this.t7AddressMessage = message;
  350. this.startT7();
  351. }
  352. /**
  353. * @return
  354. */
  355. private void stoptXAMTimers() {
  356. cancelT7();
  357. }
  358. /**
  359. * @param encoded
  360. * @param message
  361. */
  362. private void startBLOTimers(Mtp3TransferPrimitive encoded, BlockingMessage message) {
  363. this.t12t13BLO = message;
  364. this.t12t13encodedBLO = encoded;
  365. // it is started always.
  366. startT12();
  367. if (this.t13 == null) {
  368. startT13();
  369. }
  370. }
  371. /**
  372. * @return
  373. */
  374. private void stoptBLOTimers() {
  375. cancelT12();
  376. cancelT13();
  377. }
  378. /**
  379. * @param encoded
  380. * @param message
  381. */
  382. private void startUBLTimers(Mtp3TransferPrimitive encoded, UnblockingMessage message) {
  383. this.t14t15UBL = message;
  384. this.t14t15encodedUBL = encoded;
  385. // it is started always.
  386. startT14();
  387. if (this.t15 == null) {
  388. startT15();
  389. }
  390. }
  391. /**
  392. * @return
  393. */
  394. private void stoptUBLTimers() {
  395. cancelT14();
  396. cancelT15();
  397. }
  398. /**
  399. * @param encoded
  400. * @param message
  401. */
  402. private void startRSCTimers(Mtp3TransferPrimitive encoded, ResetCircuitMessage message) {
  403. this.t16t17RSC = message;
  404. this.t16t17encodedRSC = encoded;
  405. // it is started always.
  406. startT16();
  407. if (this.t17 == null) {
  408. startT17();
  409. }
  410. }
  411. /**
  412. * @return
  413. */
  414. private void stopRSCTimers() {
  415. cancelT16();
  416. cancelT17();
  417. }
  418. /**
  419. * @param encoded
  420. * @param message
  421. */
  422. private void startINRTimers(InformationRequestMessage message) {
  423. this.t33INR = message;
  424. startT33();
  425. }
  426. /**
  427. * @return
  428. */
  429. private void stoptINRTimers() {
  430. cancelT33();
  431. }
  432. /**
  433. * @param encoded
  434. * @param message
  435. */
  436. private void startCQMTimers(CircuitGroupQueryMessage message) {
  437. this.t28CQM = message;
  438. // it is started always.
  439. startT28();
  440. // FIXME: can we send more than one?
  441. }
  442. /**
  443. * @return
  444. */
  445. private void stoptCQMTimers() {
  446. cancelT28();
  447. }
  448. /**
  449. * @param encoded
  450. * @param message
  451. */
  452. private void startGRSTimers(Mtp3TransferPrimitive encoded, CircuitGroupResetMessage message) {
  453. this.t22t23GRS = message;
  454. this.t22t23encodedGRS = encoded;
  455. // it is started always.
  456. startT22();
  457. if (this.t23 == null) {
  458. startT23();
  459. }
  460. }
  461. /**
  462. * @return
  463. */
  464. private void stoptGRSTimers() {
  465. cancelT22();
  466. cancelT23();
  467. }
  468. /**
  469. * @param encoded
  470. * @param message
  471. */
  472. private void startCGUTimers(Mtp3TransferPrimitive encoded, CircuitGroupUnblockingMessage message) {
  473. this.t20t21CGU = message;
  474. this.t20t21encodedCGU = encoded;
  475. // it is started always.
  476. startT20();
  477. if (this.t21 == null) {
  478. startT21();
  479. }
  480. }
  481. /**
  482. * @return
  483. */
  484. private void stoptCGUTimers() {
  485. cancelT20();
  486. cancelT21();
  487. }
  488. /**
  489. * @param encoded
  490. * @param message
  491. */
  492. private void startCGBTimers(Mtp3TransferPrimitive encoded, CircuitGroupBlockingMessage message) {
  493. this.t18t19CGB = message;
  494. this.t18t19encodedCGB = encoded;
  495. // it is started always.
  496. startT18();
  497. if (this.t19 == null) {
  498. startT19();
  499. }
  500. }
  501. /**
  502. * @return
  503. */
  504. private void stoptCGBTimers() {
  505. cancelT18();
  506. cancelT19();
  507. }
  508. private void startT1() {
  509. cancelT1();
  510. this.t1 = this.executor.schedule(new TimerT1(), this.provider.getT1Timeout(), TimeUnit.MILLISECONDS);
  511. }
  512. private boolean cancelT1() {
  513. if (this.t1 != null) {
  514. this.t1.cancel(false);
  515. this.t1 = null;
  516. return true;
  517. } else {
  518. return false;
  519. }
  520. }
  521. private void startT5() {
  522. cancelT5();
  523. this.t5 = this.executor.schedule(new TimerT5(), this.provider.getT5Timeout(), TimeUnit.MILLISECONDS);
  524. }
  525. private boolean cancelT5() {
  526. if (this.t5 != null) {
  527. this.t5.cancel(false);
  528. this.t5 = null;
  529. return true;
  530. } else {
  531. return false;
  532. }
  533. }
  534. private void startT7() {
  535. cancelT7();
  536. this.t7 = this.executor.schedule(new TimerT7(), this.provider.getT7Timeout(), TimeUnit.MILLISECONDS);
  537. }
  538. private boolean cancelT7() {
  539. if (this.t7 != null) {
  540. this.t7.cancel(false);
  541. this.t7 = null;
  542. return true;
  543. } else {
  544. return false;
  545. }
  546. }
  547. private void startT12() {
  548. cancelT12();
  549. this.t12 = this.executor.schedule(new TimerT12(), this.provider.getT12Timeout(), TimeUnit.MILLISECONDS);
  550. }
  551. private boolean cancelT12() {
  552. if (this.t12 != null) {
  553. this.t12.cancel(false);
  554. this.t12 = null;
  555. return true;
  556. } else {
  557. return false;
  558. }
  559. }
  560. private void startT13() {
  561. cancelT13();
  562. this.t13 = this.executor.schedule(new TimerT13(), this.provider.getT13Timeout(), TimeUnit.MILLISECONDS);
  563. }
  564. private boolean cancelT13() {
  565. if (this.t13 != null) {
  566. this.t13.cancel(false);
  567. this.t13 = null;
  568. return true;
  569. } else {
  570. return false;
  571. }
  572. }
  573. private void startT14() {
  574. cancelT14();
  575. this.t14 = this.executor.schedule(new TimerT14(), this.provider.getT14Timeout(), TimeUnit.MILLISECONDS);
  576. }
  577. private boolean cancelT14() {
  578. if (this.t14 != null) {
  579. this.t14.cancel(false);
  580. this.t14 = null;
  581. return true;
  582. } else {
  583. return false;
  584. }
  585. }
  586. private void startT15() {
  587. cancelT15();
  588. this.t15 = this.executor.schedule(new TimerT15(), this.provider.getT15Timeout(), TimeUnit.MILLISECONDS);
  589. }
  590. private boolean cancelT15() {
  591. if (this.t15 != null) {
  592. this.t15.cancel(false);
  593. this.t15 = null;
  594. return true;
  595. } else {
  596. return false;
  597. }
  598. }
  599. private void startT16() {
  600. cancelT16();
  601. this.t16 = this.executor.schedule(new TimerT16(), this.provider.getT16Timeout(), TimeUnit.MILLISECONDS);
  602. }
  603. private boolean cancelT16() {
  604. if (this.t16 != null) {
  605. this.t16.cancel(false);
  606. this.t16 = null;
  607. return true;
  608. } else {
  609. return false;
  610. }
  611. }
  612. private void startT17() {
  613. cancelT17();
  614. this.t17 = this.executor.schedule(new TimerT17(), this.provider.getT17Timeout(), TimeUnit.MILLISECONDS);
  615. }
  616. private boolean cancelT17() {
  617. if (this.t17 != null) {
  618. this.t17.cancel(false);
  619. this.t17 = null;
  620. return true;
  621. } else {
  622. return false;
  623. }
  624. }
  625. private void startT18() {
  626. cancelT18();
  627. this.t18 = this.executor.schedule(new TimerT18(), this.provider.getT18Timeout(), TimeUnit.MILLISECONDS);
  628. }
  629. private boolean cancelT18() {
  630. if (this.t18 != null) {
  631. this.t18.cancel(false);
  632. this.t18 = null;
  633. return true;
  634. } else {
  635. return false;
  636. }
  637. }
  638. private void startT19() {
  639. cancelT19();
  640. this.t19 = this.executor.schedule(new TimerT19(), this.provider.getT19Timeout(), TimeUnit.MILLISECONDS);
  641. }
  642. private boolean cancelT19() {
  643. if (this.t19 != null) {
  644. this.t19.cancel(false);
  645. this.t19 = null;
  646. return true;
  647. } else {
  648. return false;
  649. }
  650. }
  651. private void startT20() {
  652. cancelT20();
  653. this.t20 = this.executor.schedule(new TimerT20(), this.provider.getT20Timeout(), TimeUnit.MILLISECONDS);
  654. }
  655. private boolean cancelT20() {
  656. if (this.t20 != null) {
  657. this.t20.cancel(false);
  658. this.t20 = null;
  659. return true;
  660. } else {
  661. return false;
  662. }
  663. }
  664. private void startT21() {
  665. cancelT21();
  666. this.t21 = this.executor.schedule(new TimerT21(), this.provider.getT21Timeout(), TimeUnit.MILLISECONDS);
  667. }
  668. private boolean cancelT21() {
  669. if (this.t21 != null) {
  670. this.t21.cancel(false);
  671. this.t21 = null;
  672. return true;
  673. } else {
  674. return false;
  675. }
  676. }
  677. private void startT22() {
  678. cancelT22();
  679. this.t22 = this.executor.schedule(new TimerT22(), this.provider.getT22Timeout(), TimeUnit.MILLISECONDS);
  680. }
  681. private boolean cancelT22() {
  682. if (this.t22 != null) {
  683. this.t22.cancel(false);
  684. this.t22 = null;
  685. return true;
  686. } else {
  687. return false;
  688. }
  689. }
  690. private void startT23() {
  691. cancelT23();
  692. this.t23 = this.executor.schedule(new TimerT23(), this.provider.getT23Timeout(), TimeUnit.MILLISECONDS);
  693. }
  694. private boolean cancelT23() {
  695. if (this.t23 != null) {
  696. this.t23.cancel(false);
  697. this.t23 = null;
  698. return true;
  699. } else {
  700. return false;
  701. }
  702. }
  703. private void startT28() {
  704. cancelT28();
  705. this.t28 = this.executor.schedule(new TimerT28(), this.provider.getT28Timeout(), TimeUnit.MILLISECONDS);
  706. }
  707. private boolean cancelT28() {
  708. if (this.t28 != null) {
  709. this.t28.cancel(false);
  710. this.t28 = null;
  711. return true;
  712. } else {
  713. return false;
  714. }
  715. }
  716. private void startT33() {
  717. cancelT33();
  718. this.t33 = this.executor.schedule(new TimerT33(), this.provider.getT33Timeout(), TimeUnit.MILLISECONDS);
  719. }
  720. private boolean cancelT33() {
  721. if (this.t33 != null) {
  722. this.t33.cancel(false);
  723. this.t33 = null;
  724. return true;
  725. } else {
  726. return false;
  727. }
  728. }
  729. private class TimerT1 implements Runnable {
  730. /*
  731. * (non-Javadoc)
  732. *
  733. * @see java.lang.Runnable#run()
  734. */
  735. public void run() {
  736. try {
  737. lock.lock();
  738. // remove us
  739. t1 = null;
  740. // start T1
  741. startT1();
  742. // send
  743. provider.send(t1t5encodedREL);
  744. // notify user
  745. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t1t5REL, ISUPTimeoutEvent.T1);
  746. provider.deliver(timeoutEvent);
  747. } catch (Exception e) {
  748. e.printStackTrace();
  749. } finally {
  750. lock.unlock();
  751. }
  752. }
  753. }
  754. private class TimerT5 implements Runnable {
  755. /*
  756. * (non-Javadoc)
  757. *
  758. * @see java.lang.Runnable#run()
  759. */
  760. public void run() {
  761. try {
  762. lock.lock();
  763. // remove t5, its current runnable.
  764. t5 = null;
  765. // cancel T1
  766. cancelT1();
  767. // restart T5
  768. startT5();
  769. // send
  770. ResetCircuitMessage rcm = provider.getMessageFactory().createRSC(cic);
  771. // avoid provider method, since we dont want other timer to be
  772. // setup.
  773. provider.sendMessage(rcm);
  774. // notify user
  775. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t1t5REL, ISUPTimeoutEvent.T5);
  776. provider.deliver(timeoutEvent);
  777. } catch (Exception e) {
  778. e.printStackTrace();
  779. } finally {
  780. lock.unlock();
  781. }
  782. }
  783. }
  784. private class TimerT7 implements Runnable {
  785. /*
  786. * (non-Javadoc)
  787. *
  788. * @see java.lang.Runnable#run()
  789. */
  790. public void run() {
  791. try {
  792. lock.lock();
  793. t7 = null;
  794. // send REL
  795. ReleaseMessage rel = provider.getMessageFactory().createREL(cic);
  796. try {
  797. CauseIndicators ci = provider.getParameterFactory().createCauseIndicators();
  798. // TODO: add CI values
  799. rel.setCauseIndicators(ci);
  800. provider.sendMessage(rel);
  801. } catch (ParameterException e) {
  802. // TODO Auto-generated catch block
  803. e.printStackTrace();
  804. } catch (IOException e) {
  805. // TODO Auto-generated catch block
  806. e.printStackTrace();
  807. }
  808. // notify user
  809. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t7AddressMessage, ISUPTimeoutEvent.T7);
  810. t7AddressMessage = null;
  811. provider.deliver(timeoutEvent);
  812. } catch (Exception e) {
  813. e.printStackTrace();
  814. } finally {
  815. lock.unlock();
  816. }
  817. }
  818. }
  819. private class TimerT12 implements Runnable {
  820. /*
  821. * (non-Javadoc)
  822. *
  823. * @see java.lang.Runnable#run()
  824. */
  825. public void run() {
  826. try {
  827. lock.lock();
  828. // remove us
  829. t12 = null;
  830. // start T12
  831. startT12();
  832. // send
  833. provider.send(t12t13encodedBLO);
  834. // notify user
  835. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t12t13BLO, ISUPTimeoutEvent.T12);
  836. provider.deliver(timeoutEvent);
  837. } catch (Exception e) {
  838. e.printStackTrace();
  839. } finally {
  840. lock.unlock();
  841. }
  842. }
  843. }
  844. private class TimerT13 implements Runnable {
  845. /*
  846. * (non-Javadoc)
  847. *
  848. * @see java.lang.Runnable#run()
  849. */
  850. public void run() {
  851. try {
  852. lock.lock();
  853. // remove t13, its current runnable.
  854. t13 = null;
  855. // cancel T12
  856. cancelT12();
  857. // restart T13
  858. startT13();
  859. // send
  860. provider.send(t12t13encodedBLO);
  861. // notify user
  862. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t12t13BLO, ISUPTimeoutEvent.T13);
  863. provider.deliver(timeoutEvent);
  864. } catch (Exception e) {
  865. e.printStackTrace();
  866. } finally {
  867. lock.unlock();
  868. }
  869. }
  870. }
  871. private class TimerT14 implements Runnable {
  872. /*
  873. * (non-Javadoc)
  874. *
  875. * @see java.lang.Runnable#run()
  876. */
  877. public void run() {
  878. try {
  879. lock.lock();
  880. // remove us
  881. t14 = null;
  882. // start T14
  883. startT14();
  884. // send
  885. provider.send(t14t15encodedUBL);
  886. // notify user
  887. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t14t15UBL, ISUPTimeoutEvent.T14);
  888. provider.deliver(timeoutEvent);
  889. } catch (Exception e) {
  890. e.printStackTrace();
  891. } finally {
  892. lock.unlock();
  893. }
  894. }
  895. }
  896. private class TimerT15 implements Runnable {
  897. /*
  898. * (non-Javadoc)
  899. *
  900. * @see java.lang.Runnable#run()
  901. */
  902. public void run() {
  903. try {
  904. lock.lock();
  905. // remove t15, its current runnable.
  906. t15 = null;
  907. // cancel T14
  908. cancelT14();
  909. // start
  910. startT15();
  911. // send
  912. provider.send(t14t15encodedUBL);
  913. // notify user
  914. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t14t15UBL, ISUPTimeoutEvent.T15);
  915. provider.deliver(timeoutEvent);
  916. } catch (Exception e) {
  917. e.printStackTrace();
  918. } finally {
  919. lock.unlock();
  920. }
  921. }
  922. }
  923. private class TimerT16 implements Runnable {
  924. /*
  925. * (non-Javadoc)
  926. *
  927. * @see java.lang.Runnable#run()
  928. */
  929. public void run() {
  930. try {
  931. lock.lock();
  932. // remove us
  933. t16 = null;
  934. // start T14
  935. startT16();
  936. // send
  937. provider.send(t16t17encodedRSC);
  938. // notify user
  939. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t16t17RSC, ISUPTimeoutEvent.T16);
  940. provider.deliver(timeoutEvent);
  941. } catch (Exception e) {
  942. e.printStackTrace();
  943. } finally {
  944. lock.unlock();
  945. }
  946. }
  947. }
  948. private class TimerT17 implements Runnable {
  949. /*
  950. * (non-Javadoc)
  951. *
  952. * @see java.lang.Runnable#run()
  953. */
  954. public void run() {
  955. try {
  956. lock.lock();
  957. // remove t17, its current runnable.
  958. t17 = null;
  959. // cancel T16
  960. cancelT16();
  961. // restart T17
  962. startT17();
  963. // send
  964. provider.send(t16t17encodedRSC);
  965. // notify user
  966. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t16t17RSC, ISUPTimeoutEvent.T17);
  967. provider.deliver(timeoutEvent);
  968. } catch (Exception e) {
  969. e.printStackTrace();
  970. } finally {
  971. lock.unlock();
  972. }
  973. }
  974. }
  975. private class TimerT18 implements Runnable {
  976. /*
  977. * (non-Javadoc)
  978. *
  979. * @see java.lang.Runnable#run()
  980. */
  981. public void run() {
  982. try {
  983. lock.lock();
  984. // remove us
  985. t18 = null;
  986. // start T18
  987. startT18();
  988. // send
  989. provider.send(t18t19encodedCGB);
  990. // notify user
  991. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t18t19CGB, ISUPTimeoutEvent.T18);
  992. provider.deliver(timeoutEvent);
  993. } catch (Exception e) {
  994. e.printStackTrace();
  995. } finally {
  996. lock.unlock();
  997. }
  998. }
  999. }
  1000. private class TimerT19 implements Runnable {
  1001. /*
  1002. * (non-Javadoc)
  1003. *
  1004. * @see java.lang.Runnable#run()
  1005. */
  1006. public void run() {
  1007. try {
  1008. lock.lock();
  1009. // remove t19, its current runnable.
  1010. t19 = null;
  1011. // cancel T18
  1012. cancelT18();
  1013. // restart T19
  1014. startT19();
  1015. // send
  1016. provider.send(t18t19encodedCGB);
  1017. // notify user
  1018. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t18t19CGB, ISUPTimeoutEvent.T19);
  1019. provider.deliver(timeoutEvent);
  1020. } catch (Exception e) {
  1021. e.printStackTrace();
  1022. } finally {
  1023. lock.unlock();
  1024. }
  1025. }
  1026. }
  1027. private class TimerT20 implements Runnable {
  1028. /*
  1029. * (non-Javadoc)
  1030. *
  1031. * @see java.lang.Runnable#run()
  1032. */
  1033. public void run() {
  1034. try {
  1035. lock.lock();
  1036. // remove us
  1037. t20 = null;
  1038. // start T20
  1039. startT20();
  1040. // send
  1041. provider.send(t20t21encodedCGU);
  1042. // notify user
  1043. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t20t21CGU, ISUPTimeoutEvent.T20);
  1044. provider.deliver(timeoutEvent);
  1045. } catch (Exception e) {
  1046. e.printStackTrace();
  1047. } finally {
  1048. lock.unlock();
  1049. }
  1050. }
  1051. }
  1052. private class TimerT21 implements Runnable {
  1053. /*
  1054. * (non-Javadoc)
  1055. *
  1056. * @see java.lang.Runnable#run()
  1057. */
  1058. public void run() {
  1059. try {
  1060. lock.lock();
  1061. // remove t21, its current runnable.
  1062. t21 = null;
  1063. // cancel T20
  1064. cancelT20();
  1065. // restart T21
  1066. startT21();
  1067. // send
  1068. provider.send(t20t21encodedCGU);
  1069. // notify user
  1070. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t20t21CGU, ISUPTimeoutEvent.T21);
  1071. provider.deliver(timeoutEvent);
  1072. } catch (Exception e) {
  1073. e.printStackTrace();
  1074. } finally {
  1075. lock.unlock();
  1076. }
  1077. }
  1078. }
  1079. private class TimerT22 implements Runnable {
  1080. /*
  1081. * (non-Javadoc)
  1082. *
  1083. * @see java.lang.Runnable#run()
  1084. */
  1085. public void run() {
  1086. try {
  1087. lock.lock();
  1088. // remove us
  1089. t22 = null;
  1090. // start T22
  1091. startT22();
  1092. // send
  1093. provider.send(t22t23encodedGRS);
  1094. // notify user
  1095. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t22t23GRS, ISUPTimeoutEvent.T22);
  1096. provider.deliver(timeoutEvent);
  1097. } catch (Exception e) {
  1098. e.printStackTrace();
  1099. } finally {
  1100. lock.unlock();
  1101. }
  1102. }
  1103. }
  1104. private class TimerT23 implements Runnable {
  1105. /*
  1106. * (non-Javadoc)
  1107. *
  1108. * @see java.lang.Runnable#run()
  1109. */
  1110. public void run() {
  1111. try {
  1112. lock.lock();
  1113. // remove t23, its current runnable.
  1114. t23 = null;
  1115. // cancel T22
  1116. cancelT22();
  1117. // restart T23
  1118. startT23();
  1119. // send
  1120. provider.send(t22t23encodedGRS);
  1121. // notify user
  1122. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t22t23GRS, ISUPTimeoutEvent.T23);
  1123. provider.deliver(timeoutEvent);
  1124. } catch (Exception e) {
  1125. e.printStackTrace();
  1126. } finally {
  1127. lock.unlock();
  1128. }
  1129. }
  1130. }
  1131. private class TimerT28 implements Runnable {
  1132. /*
  1133. * (non-Javadoc)
  1134. *
  1135. * @see java.lang.Runnable#run()
  1136. */
  1137. public void run() {
  1138. try {
  1139. lock.lock();
  1140. // remove us
  1141. t28 = null;
  1142. // notify user
  1143. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t28CQM, ISUPTimeoutEvent.T28);
  1144. provider.deliver(timeoutEvent);
  1145. t28CQM = null;
  1146. } catch (Exception e) {
  1147. e.printStackTrace();
  1148. } finally {
  1149. lock.unlock();
  1150. }
  1151. }
  1152. }
  1153. private class TimerT33 implements Runnable {
  1154. /*
  1155. * (non-Javadoc)
  1156. *
  1157. * @see java.lang.Runnable#run()
  1158. */
  1159. public void run() {
  1160. try {
  1161. lock.lock();
  1162. // remove us
  1163. t33 = null;
  1164. // notify user
  1165. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(provider, t33INR, ISUPTimeoutEvent.T33);
  1166. provider.deliver(timeoutEvent);
  1167. // FIXME: do this after call, to prevent send of another msg
  1168. t33INR = null;
  1169. // send REL
  1170. ReleaseMessage rel = provider.getMessageFactory().createREL(cic);
  1171. try {
  1172. CauseIndicators ci = provider.getParameterFactory().createCauseIndicators();
  1173. // TODO: add CI values
  1174. rel.setCauseIndicators(ci);
  1175. provider.sendMessage(rel);
  1176. } catch (ParameterException e) {
  1177. // TODO Auto-generated catch block
  1178. e.printStackTrace();
  1179. } catch (IOException e) {
  1180. // TODO Auto-generated catch block
  1181. e.printStackTrace();
  1182. }
  1183. } catch (Exception e) {
  1184. e.printStackTrace();
  1185. } finally {
  1186. lock.unlock();
  1187. }
  1188. }
  1189. }
  1190. /**
  1191. *
  1192. */
  1193. public void onStop() {
  1194. try {
  1195. lock.lock();
  1196. cancelT1();
  1197. cancelT5();
  1198. cancelT12();
  1199. cancelT13();
  1200. cancelT14();
  1201. cancelT15();
  1202. cancelT16();
  1203. cancelT17();
  1204. cancelT18();
  1205. cancelT19();
  1206. cancelT20();
  1207. cancelT21();
  1208. cancelT22();
  1209. cancelT23();
  1210. cancelT28();
  1211. cancelT33();
  1212. } finally {
  1213. lock.unlock();
  1214. }
  1215. }
  1216. }