PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/app/gq/GqClientSessionImpl.java

http://mobicents.googlecode.com/
Java | 655 lines | 469 code | 52 blank | 134 comment | 71 complexity | 9ff98e935c1b1546682882455571257f 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.jdiameter.client.impl.app.gq;
  23. import static org.jdiameter.api.Message.SESSION_TERMINATION_REQUEST;
  24. import static org.jdiameter.common.api.app.auth.ClientAuthSessionState.DISCONNECTED;
  25. import static org.jdiameter.common.api.app.auth.ClientAuthSessionState.IDLE;
  26. import static org.jdiameter.common.api.app.auth.ClientAuthSessionState.OPEN;
  27. import static org.jdiameter.common.api.app.auth.ClientAuthSessionState.PENDING;
  28. import java.io.Serializable;
  29. import java.util.concurrent.locks.Lock;
  30. import java.util.concurrent.locks.ReentrantLock;
  31. import org.jdiameter.api.Answer;
  32. import org.jdiameter.api.Avp;
  33. import org.jdiameter.api.AvpSet;
  34. import org.jdiameter.api.EventListener;
  35. import org.jdiameter.api.IllegalDiameterStateException;
  36. import org.jdiameter.api.InternalException;
  37. import org.jdiameter.api.NetworkReqListener;
  38. import org.jdiameter.api.OverloadException;
  39. import org.jdiameter.api.Request;
  40. import org.jdiameter.api.RouteException;
  41. import org.jdiameter.api.app.AppAnswerEvent;
  42. import org.jdiameter.api.app.AppEvent;
  43. import org.jdiameter.api.app.AppRequestEvent;
  44. import org.jdiameter.api.app.AppSession;
  45. import org.jdiameter.api.app.StateChangeListener;
  46. import org.jdiameter.api.app.StateEvent;
  47. import org.jdiameter.api.gq.GqClientSession;
  48. import org.jdiameter.api.auth.ClientAuthSessionListener;
  49. import org.jdiameter.api.auth.events.AbortSessionAnswer;
  50. import org.jdiameter.api.auth.events.AbortSessionRequest;
  51. import org.jdiameter.api.auth.events.ReAuthAnswer;
  52. import org.jdiameter.api.auth.events.ReAuthRequest;
  53. import org.jdiameter.api.auth.events.SessionTermAnswer;
  54. import org.jdiameter.api.auth.events.SessionTermRequest;
  55. import org.jdiameter.client.api.ISessionFactory;
  56. import org.jdiameter.common.api.app.IAppSessionState;
  57. import org.jdiameter.common.api.app.auth.ClientAuthSessionState;
  58. import org.jdiameter.common.api.app.auth.IAuthMessageFactory;
  59. import org.jdiameter.common.api.app.auth.IClientAuthActionContext;
  60. import org.jdiameter.common.impl.app.AppAnswerEventImpl;
  61. import org.jdiameter.common.impl.app.AppRequestEventImpl;
  62. import org.jdiameter.common.impl.app.auth.AbortSessionAnswerImpl;
  63. import org.jdiameter.common.impl.app.auth.AbortSessionRequestImpl;
  64. import org.jdiameter.common.impl.app.auth.AppAuthSessionImpl;
  65. import org.jdiameter.common.impl.app.auth.ReAuthAnswerImpl;
  66. import org.jdiameter.common.impl.app.auth.ReAuthRequestImpl;
  67. import org.jdiameter.common.impl.app.auth.SessionTermAnswerImpl;
  68. import org.jdiameter.common.impl.app.auth.SessionTermRequestImpl;
  69. import org.jdiameter.client.impl.app.auth.IClientAuthSessionData;
  70. import org.slf4j.Logger;
  71. import org.slf4j.LoggerFactory;
  72. /**
  73. * Client Gq Application session implementation
  74. *
  75. * @author <a href="mailto:webdev@web-ukraine.info"> Yulian Oifa </a>
  76. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  77. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  78. */
  79. public class GqClientSessionImpl extends AppAuthSessionImpl implements GqClientSession, EventListener<Request, Answer>, NetworkReqListener {
  80. protected static final Logger logger = LoggerFactory.getLogger(GqClientSessionImpl.class);
  81. // Session State Handling ---------------------------------------------------
  82. protected Lock sendAndStateLock = new ReentrantLock();
  83. // Factories and Listeners --------------------------------------------------
  84. protected transient IAuthMessageFactory factory;
  85. protected transient IClientAuthActionContext context;
  86. protected transient ClientAuthSessionListener listener;
  87. protected static final String TIMER_NAME_TS = "GQ_TS";
  88. protected IClientAuthSessionData sessionData;
  89. // Constructors -------------------------------------------------------------
  90. public GqClientSessionImpl(IClientAuthSessionData sessionData,ISessionFactory sf,ClientAuthSessionListener lst, IAuthMessageFactory fct, StateChangeListener<AppSession> scListener,IClientAuthActionContext context, boolean stateless) {
  91. super(sf, sessionData);
  92. if (lst == null) {
  93. throw new IllegalArgumentException("Listener can not be null");
  94. }
  95. if (fct.getApplicationId() == null) {
  96. throw new IllegalArgumentException("ApplicationId can not be null");
  97. }
  98. super.appId = fct.getApplicationId();
  99. this.listener = lst;
  100. this.factory = fct;
  101. this.context = context;
  102. this.sessionData = sessionData;
  103. this.sessionData.setStateless(stateless);
  104. super.addStateChangeNotification(scListener);
  105. }
  106. // ClientAuthSession Implementation methods ---------------------------------
  107. public void sendAbortSessionAnswer(AbortSessionAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  108. send(Event.Type.SEND_SESSION_ABORT_ANSWER, answer);
  109. }
  110. public void sendAuthRequest(AppRequestEvent request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  111. send(Event.Type.SEND_AUTH_REQUEST, request);
  112. }
  113. public void sendReAuthAnswer(ReAuthAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  114. send(Event.Type.SEND_AUTH_ANSWER, answer);
  115. }
  116. public void sendSessionTerminationRequest(SessionTermRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  117. send(Event.Type.SEND_SESSION_TERMINATION_REQUEST, request);
  118. }
  119. protected void send(Event.Type type, AppEvent event) throws InternalException {
  120. //This is called from app thread, it may be due to callback from our delivery thread, but we dont care
  121. try {
  122. sendAndStateLock.lock();
  123. if (type != null) {
  124. handleEvent(new Event(type, event));
  125. }
  126. session.send(event.getMessage(), this);
  127. // Store last destination information
  128. AvpSet avps = event.getMessage().getAvps();
  129. Avp destRealmAvp = avps.getAvp(Avp.DESTINATION_REALM);
  130. if(destRealmAvp != null) {
  131. sessionData.setDestinationRealm(destRealmAvp.getDiameterIdentity());
  132. }
  133. Avp destHostAvp = avps.getAvp(Avp.DESTINATION_HOST);
  134. if(destHostAvp != null) {
  135. sessionData.setDestinationHost(destHostAvp.getDiameterIdentity());
  136. }
  137. }
  138. catch (Exception e) {
  139. throw new InternalException(e);
  140. }
  141. finally {
  142. sendAndStateLock.unlock();
  143. }
  144. }
  145. public boolean isStateless() {
  146. return this.sessionData.isStateless();
  147. }
  148. @SuppressWarnings("unchecked")
  149. protected void setState(ClientAuthSessionState newState) {
  150. IAppSessionState oldState = sessionData.getClientAuthSessionState();
  151. sessionData.setClientAuthSessionState(newState);
  152. for (StateChangeListener i : stateListeners) {
  153. i.stateChanged(this,(Enum) oldState, (Enum) newState);
  154. }
  155. }
  156. @SuppressWarnings("unchecked")
  157. public <E> E getState(Class<E> eClass) {
  158. return eClass == ClientAuthSessionState.class ? (E) sessionData.getClientAuthSessionState() : null;
  159. }
  160. public boolean handleEvent(StateEvent event) throws InternalException, OverloadException {
  161. return sessionData.isStateless() ? handleEventForStatelessSession(event) : handleEventForStatefulSession(event);
  162. }
  163. public boolean handleEventForStatelessSession(StateEvent event) throws InternalException, OverloadException {
  164. try {
  165. ClientAuthSessionState state = sessionData.getClientAuthSessionState();
  166. ClientAuthSessionState oldState = state;
  167. switch (state) {
  168. case IDLE:
  169. switch ((Event.Type) event.getType()) {
  170. case SEND_AUTH_REQUEST:
  171. // Current State: IDLE
  172. // Event: Client or Device Requests access
  173. // Action: Send service specific auth req
  174. // New State: PENDING
  175. setState(PENDING);
  176. break;
  177. default:
  178. logger.debug("Unknown event [{}]", event.getType());
  179. break;
  180. }
  181. break;
  182. case PENDING:
  183. switch ((Event.Type) event.getType()) {
  184. case RECEIVE_AUTH_ANSWER:
  185. try {
  186. // Current State: PENDING
  187. // Event: Successful service-specific authorization answer received with Auth-Session-State set to NO_STATE_MAINTAINED
  188. // Action: Grant Access
  189. // New State: OPEN
  190. listener.doAuthAnswerEvent(this, null, (AppAnswerEvent) event.getData());
  191. setState(OPEN);
  192. }
  193. catch (Exception e) {
  194. // Current State: PENDING
  195. // Event: Failed service-specific authorization answer received
  196. // Action: Cleanup
  197. // New State: IDLE
  198. setState(IDLE);
  199. }
  200. break;
  201. case SEND_SESSION_TERMINATION_REQUEST:
  202. // Current State: OPEN
  203. // Event: Service to user is terminated
  204. // Action: Disconnect User/Device
  205. // New State: IDLE
  206. setState(IDLE);
  207. break;
  208. default:
  209. logger.debug("Unknown event [{}]", event.getType());
  210. break;
  211. }
  212. break;
  213. case OPEN:
  214. switch ((Event.Type) event.getType()) {
  215. case SEND_SESSION_ABORT_ANSWER:
  216. case SEND_SESSION_TERMINATION_REQUEST:
  217. // Current State: OPEN
  218. // Event: Service to user is terminated
  219. // Action: Disconnect User/Device
  220. // New State: IDLE
  221. setState(IDLE);
  222. break;
  223. case TIMEOUT_EXPIRES:
  224. // Current State: OPEN
  225. // Event: Session-Timeout Expires on Access Device
  226. // Action: Send STR
  227. // New State: DISCON
  228. if (context != null) {
  229. context.accessTimeoutElapses(this);
  230. Request str = createSessionTermRequest();
  231. context.disconnectUserOrDev(this, str);
  232. session.send(str, this);
  233. }
  234. // IDLE is the same as DISCON
  235. setState(IDLE);
  236. break;
  237. default:
  238. logger.debug("Unknown event [{}]", event.getType());
  239. break;
  240. }
  241. break;
  242. }
  243. // post processing
  244. if (oldState != state) {
  245. if (DISCONNECTED.equals(state) || IDLE.equals(state)) {
  246. cancelTsTimer();
  247. }
  248. else if (OPEN.equals(state) && context != null && context.getAccessTimeout() > 0) {
  249. cancelTsTimer();
  250. startTsTimer();
  251. }
  252. }
  253. }
  254. catch (Throwable t) {
  255. throw new InternalException(t);
  256. }
  257. return true;
  258. }
  259. public boolean handleEventForStatefulSession(StateEvent event) throws InternalException, OverloadException {
  260. ClientAuthSessionState state = sessionData.getClientAuthSessionState();
  261. ClientAuthSessionState oldState = state;
  262. try {
  263. switch (state) {
  264. case IDLE: {
  265. switch ((Event.Type) event.getType()) {
  266. case SEND_AUTH_REQUEST:
  267. // Current State: IDLE
  268. // Event: Client or Device Requests access
  269. // Action: Send service specific auth req
  270. // New State: PENDING
  271. setState(PENDING);
  272. break;
  273. case RECEIVE_ABORT_SESSION_REQUEST:
  274. // Current State: IDLE
  275. // Event: ASR Received for unknown session
  276. // Action: Send ASA with Result-Code = UNKNOWN_SESSION_ID
  277. // New State: IDLE
  278. // FIXME: Should send ASA with UNKNOWN_SESSION_ID instead ?
  279. listener.doAbortSessionRequestEvent(this, (AbortSessionRequest) event.getData());
  280. break;
  281. default:
  282. logger.debug("Unknown event [{}]", event.getType());
  283. break;
  284. }
  285. break;
  286. }
  287. case PENDING: {
  288. switch ((Event.Type) event.getType()) {
  289. case RECEIVE_AUTH_ANSWER:
  290. try {
  291. // Current State: PENDING
  292. // Event: Successful service-specific authorization answer received with default Auth-Session-State value
  293. // Action: Grant Access
  294. // New State: OPEN
  295. listener.doAuthAnswerEvent(this, null, (AppAnswerEvent) event.getData());
  296. setState(OPEN);
  297. }
  298. catch (InternalException e) {
  299. // Current State: PENDING
  300. // Event: Successful service-specific authorization answer received but service not provided
  301. // Action: Send STR
  302. // New State: DISCON
  303. // Current State: PENDING
  304. // Event: Error Processing successful service-specific authorization answer
  305. // Action: Send STR
  306. // New State: DISCON
  307. setState(DISCONNECTED);
  308. }
  309. catch (Exception e) {
  310. // Current State: PENDING
  311. // Event: Failed service-specific authorization answer received
  312. // Action: Cleanup
  313. // New State: IDLE
  314. setState(IDLE);
  315. }
  316. break;
  317. case SEND_SESSION_TERMINATION_REQUEST:
  318. // Current State: OPEN
  319. // Event: Service to user is terminated
  320. // Action: Disconnect User/Device
  321. // New State: IDLE
  322. setState(DISCONNECTED);
  323. break;
  324. default:
  325. logger.debug("Unknown event [{}]", event.getType());
  326. break;
  327. }
  328. break;
  329. }
  330. case OPEN: {
  331. switch ((Event.Type) event.getType()) {
  332. case SEND_AUTH_REQUEST:
  333. // Current State: OPEN
  334. // Event: User or client device requests access to service
  335. // Action: Send service specific auth req
  336. // New State: OPEN
  337. break;
  338. case RECEIVE_AUTH_ANSWER:
  339. try {
  340. // Current State: OPEN
  341. // Event: Successful service-specific authorization answer received
  342. // Action: Provide Service
  343. // New State: OPEN
  344. listener.doAuthAnswerEvent(this, null, (AppAnswerEvent) event.getData());
  345. }
  346. catch (Exception e) {
  347. // Current State: OPEN
  348. // Event: ASR Received, client will comply with request to end the session
  349. // Action: Send ASA with Result-Code = SUCCESS, Send STR
  350. // New State: DISCON
  351. setState(DISCONNECTED);
  352. }
  353. break;
  354. case RECEIVE_FAILED_AUTH_ANSWER:
  355. // Current State: OPEN
  356. // Event: Failed Service-specific authorization answer received
  357. // Action: Disconnect User/Device
  358. // New State: IDLE
  359. if (context != null) {
  360. Request str = createSessionTermRequest();
  361. context.disconnectUserOrDev(this, str);
  362. session.send(str, this);
  363. }
  364. setState(IDLE);
  365. break;
  366. case RECEIVE_ABORT_SESSION_REQUEST:
  367. // Current State: OPEN
  368. // Event: ASR Received (client to take comply or not)
  369. // Action: TBD
  370. // New State: TBD (comply = DISCON, !comply = OPEN)
  371. listener.doAbortSessionRequestEvent(this, (AbortSessionRequestImpl) event.getData());
  372. break;
  373. case SEND_SESSION_TERMINATION_REQUEST:
  374. setState(DISCONNECTED);
  375. break;
  376. case TIMEOUT_EXPIRES:
  377. // Current State: OPEN
  378. // Event: Session-Timeout Expires on Access Device
  379. // Action: Send STR
  380. // New State: DISCON
  381. // Current State: OPEN
  382. // Event: Authorization-Lifetime + Auth-Grace-Period expires on access device
  383. // Action: Send STR
  384. // New State: DISCON
  385. if (context != null) {
  386. context.accessTimeoutElapses(this);
  387. Request str = createSessionTermRequest();
  388. context.disconnectUserOrDev(this, str);
  389. session.send(str, this);
  390. }
  391. setState(DISCONNECTED);
  392. break;
  393. }
  394. break;
  395. }
  396. case DISCONNECTED: {
  397. switch ((Event.Type) event.getType()) {
  398. case RECEIVE_ABORT_SESSION_REQUEST:
  399. // Current State: DISCON
  400. // Event: ASR Received
  401. // Action: Send ASA
  402. // New State: DISCON
  403. listener.doAbortSessionRequestEvent(this, (AbortSessionRequest) event.getData());
  404. break;
  405. case RECEIVE_SESSION_TERINATION_ANSWER:
  406. // Current State: DISCON
  407. // Event: STA Received
  408. // Action: Disconnect User/Device
  409. // New State: IDLE
  410. listener.doSessionTerminationAnswerEvent(this, ((SessionTermAnswerImpl) event.getData()));
  411. setState(IDLE);
  412. break;
  413. default:
  414. logger.debug("Unknown event [{}]", event.getType());
  415. break;
  416. }
  417. break;
  418. }
  419. default: {
  420. logger.debug("Unknown state [{}]", state);
  421. break;
  422. }
  423. }
  424. // post processing
  425. if (oldState != state) {
  426. if (OPEN.equals(state) && context != null && context.getAccessTimeout() > 0) {
  427. cancelTsTimer();
  428. startTsTimer();
  429. }
  430. }
  431. }
  432. catch (Throwable t) {
  433. throw new InternalException(t);
  434. }
  435. return true;
  436. }
  437. public void receivedSuccessMessage(Request request, Answer answer) {
  438. AnswerDelivery ad = new AnswerDelivery();
  439. ad.session = this;
  440. ad.request = request;
  441. ad.answer = answer;
  442. super.scheduler.execute(ad);
  443. }
  444. public void timeoutExpired(Request request) {
  445. try {
  446. //FIXME: should this also be async ?
  447. handleEvent(new Event(Event.Type.RECEIVE_FAILED_AUTH_ANSWER, new AppRequestEventImpl(request)));
  448. }
  449. catch (Exception e) {
  450. logger.debug("Can not handle timeout event", e);
  451. }
  452. }
  453. public Answer processRequest(Request request) {
  454. RequestDelivery rd = new RequestDelivery();
  455. rd.session = this;
  456. rd.request = request;
  457. super.scheduler.execute(rd);
  458. return null;
  459. }
  460. /* (non-Javadoc)
  461. * @see org.jdiameter.common.impl.app.AppSessionImpl#isReplicable()
  462. */
  463. @Override
  464. public boolean isReplicable() {
  465. return true;
  466. }
  467. protected void startTsTimer() throws IllegalArgumentException, InternalException {
  468. try {
  469. sendAndStateLock.lock();
  470. sessionData.setTsTimerId(super.timerFacility.schedule(sessionData.getSessionId(), TIMER_NAME_TS, context.getAccessTimeout()));
  471. }
  472. finally {
  473. sendAndStateLock.unlock();
  474. }
  475. }
  476. protected void cancelTsTimer() {
  477. try {
  478. sendAndStateLock.lock();
  479. Serializable timerId = sessionData.getTsTimerId();
  480. if(timerId != null) {
  481. super.timerFacility.cancel(timerId);
  482. sessionData.setTsTimerId(null);
  483. }
  484. }
  485. finally {
  486. sendAndStateLock.unlock();
  487. }
  488. }
  489. /* (non-Javadoc)
  490. * @see org.jdiameter.common.impl.app.AppSessionImpl#onTimer(java.lang.String)
  491. */
  492. @Override
  493. public void onTimer(String timerName) {
  494. if(timerName.equals(TIMER_NAME_TS)) {
  495. try {
  496. sendAndStateLock.lock();
  497. sessionData.setTsTimerId(null);
  498. if (context != null) {
  499. try {
  500. handleEvent(new Event(Event.Type.TIMEOUT_EXPIRES, null));
  501. }
  502. catch (Exception e) {
  503. logger.debug("Can not handle event", e);
  504. }
  505. }
  506. }
  507. finally {
  508. sendAndStateLock.unlock();
  509. }
  510. }
  511. }
  512. protected AbortSessionAnswer createAbortSessionAnswer(Answer answer) {
  513. return new AbortSessionAnswerImpl(answer);
  514. }
  515. protected AbortSessionRequest createAbortSessionRequest(Request request) {
  516. return new AbortSessionRequestImpl(request);
  517. }
  518. protected ReAuthAnswer createReAuthAnswer(Answer answer) {
  519. return new ReAuthAnswerImpl(answer);
  520. }
  521. protected ReAuthRequest createReAuthRequest(Request request) {
  522. return new ReAuthRequestImpl(request);
  523. }
  524. protected SessionTermAnswer createSessionTermAnswer(Answer answer) {
  525. return new SessionTermAnswerImpl(answer);
  526. }
  527. protected SessionTermRequest createSessionTermRequest(Request request) {
  528. return new SessionTermRequestImpl(request);
  529. }
  530. protected Request createSessionTermRequest() {
  531. return session.createRequest(SESSION_TERMINATION_REQUEST, appId, sessionData.getDestinationRealm(), sessionData.getDestinationHost());
  532. }
  533. @Override
  534. public int hashCode() {
  535. final int prime = 31;
  536. int result = super.hashCode();
  537. result = prime * result + ((sessionData == null) ? 0 : sessionData.hashCode());
  538. return result;
  539. }
  540. @Override
  541. public boolean equals(Object obj) {
  542. if (this == obj)
  543. return true;
  544. if (!super.equals(obj))
  545. return false;
  546. if (getClass() != obj.getClass())
  547. return false;
  548. GqClientSessionImpl other = (GqClientSessionImpl) obj;
  549. if (sessionData == null) {
  550. if (other.sessionData != null)
  551. return false;
  552. }
  553. else if (!sessionData.equals(other.sessionData))
  554. return false;
  555. return true;
  556. }
  557. private class RequestDelivery implements Runnable {
  558. GqClientSession session;
  559. Request request;
  560. public void run() {
  561. try {
  562. if (request.getCommandCode() == AbortSessionRequestImpl.code) {
  563. handleEvent(new Event(Event.Type.RECEIVE_ABORT_SESSION_REQUEST, createAbortSessionRequest(request)));
  564. }
  565. else if (request.getCommandCode() == ReAuthRequestImpl.code) {
  566. listener.doReAuthRequestEvent(session, createReAuthRequest(request));
  567. }
  568. else {
  569. listener.doOtherEvent(session, factory.createAuthRequest(request), null);
  570. }
  571. }
  572. catch (Exception e) {
  573. logger.debug("Can not process received request", e);
  574. }
  575. }
  576. }
  577. private class AnswerDelivery implements Runnable {
  578. GqClientSession session;
  579. Answer answer;
  580. Request request;
  581. public void run() {
  582. try {
  583. sendAndStateLock.lock();
  584. // FIXME: baranowb: this shouldn't be like that?
  585. if (answer.getCommandCode() == factory.getAuthMessageCommandCode()) {
  586. handleEvent(new Event(Event.Type.RECEIVE_AUTH_ANSWER, factory.createAuthAnswer(answer)));
  587. }
  588. else if (answer.getCommandCode() == SessionTermAnswerImpl.code) {
  589. handleEvent(new Event(Event.Type.RECEIVE_SESSION_TERINATION_ANSWER, createSessionTermAnswer(answer)));
  590. }
  591. else {
  592. listener.doOtherEvent(session, factory.createAuthRequest(request), new AppAnswerEventImpl(answer));
  593. }
  594. }
  595. catch (Exception e) {
  596. logger.debug("Can not process received message", e);
  597. }
  598. finally {
  599. sendAndStateLock.unlock();
  600. }
  601. }
  602. }
  603. }