/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/as/LocalAspFactory.java
Java | 703 lines | 552 code | 94 blank | 57 comment | 104 complexity | f6603e046a4218c65f879a69808293ea MD5 | raw file
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 23package org.mobicents.protocols.ss7.m3ua.impl.as; 24 25import java.io.IOException; 26 27import javolution.util.FastList; 28import javolution.xml.XMLFormat; 29import javolution.xml.stream.XMLStreamException; 30 31import org.apache.log4j.Level; 32import org.apache.log4j.Logger; 33import org.mobicents.protocols.ss7.m3ua.M3UAProvider; 34import org.mobicents.protocols.ss7.m3ua.impl.As; 35import org.mobicents.protocols.ss7.m3ua.impl.Asp; 36import org.mobicents.protocols.ss7.m3ua.impl.AspFactory; 37import org.mobicents.protocols.ss7.m3ua.impl.AspState; 38import org.mobicents.protocols.ss7.m3ua.impl.M3UAManagement; 39import org.mobicents.protocols.ss7.m3ua.impl.TransitionState; 40import org.mobicents.protocols.ss7.m3ua.impl.fsm.UnknownTransitionException; 41import org.mobicents.protocols.ss7.m3ua.message.M3UAMessage; 42import org.mobicents.protocols.ss7.m3ua.message.MessageClass; 43import org.mobicents.protocols.ss7.m3ua.message.MessageType; 44import org.mobicents.protocols.ss7.m3ua.message.aspsm.ASPDown; 45import org.mobicents.protocols.ss7.m3ua.message.aspsm.ASPDownAck; 46import org.mobicents.protocols.ss7.m3ua.message.aspsm.ASPUp; 47import org.mobicents.protocols.ss7.m3ua.message.aspsm.ASPUpAck; 48import org.mobicents.protocols.ss7.m3ua.message.aspsm.Heartbeat; 49import org.mobicents.protocols.ss7.m3ua.message.aspsm.HeartbeatAck; 50import org.mobicents.protocols.ss7.m3ua.message.asptm.ASPActive; 51import org.mobicents.protocols.ss7.m3ua.message.asptm.ASPActiveAck; 52import org.mobicents.protocols.ss7.m3ua.message.asptm.ASPInactiveAck; 53import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify; 54import org.mobicents.protocols.ss7.m3ua.message.ssnm.DestinationAvailable; 55import org.mobicents.protocols.ss7.m3ua.message.ssnm.DestinationUPUnavailable; 56import org.mobicents.protocols.ss7.m3ua.message.ssnm.DestinationUnavailable; 57import org.mobicents.protocols.ss7.m3ua.message.ssnm.SignallingCongestion; 58import org.mobicents.protocols.ss7.m3ua.message.transfer.PayloadData; 59import org.mobicents.protocols.ss7.m3ua.parameter.ASPIdentifier; 60import org.mobicents.protocols.ss7.m3ua.parameter.AffectedPointCode; 61import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication; 62import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication.CongestionLevel; 63import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext; 64import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType; 65import org.mobicents.protocols.ss7.m3ua.parameter.UserCause; 66import org.mobicents.protocols.ss7.mtp.Mtp3PausePrimitive; 67import org.mobicents.protocols.ss7.mtp.Mtp3ResumePrimitive; 68import org.mobicents.protocols.ss7.mtp.Mtp3StatusPrimitive; 69 70/** 71 * 72 * @author amit bhayani 73 * 74 */ 75public class LocalAspFactory extends AspFactory { 76 private static final Logger logger = Logger.getLogger(LocalAspFactory.class); 77 78 private static final String REM_IP = "remIp"; 79 private static final String REM_PORT = "remPort"; 80 //private static final String CHANNEL_CONNECTED = "chanConn"; 81 82 private static long ASP_ID = 1l; 83 84 private String remIp; 85 private int remPort; 86 boolean channelConnected = false; 87 88 private ASPIdentifier aspid; 89 90 public LocalAspFactory() { 91 super(); 92 } 93 94 public LocalAspFactory(String name, String localIp, int localPort, String remIp, int remPort, M3UAProvider provider, M3UAManagement m3uaManagement) { 95 super(name, localIp, localPort, provider, m3uaManagement); 96 this.remIp = remIp; 97 this.remPort = remPort; 98 this.aspid = this.m3UAProvider.getParameterFactory().createASPIdentifier(this.generateId()); 99 } 100 101 public String getRemIp() { 102 return remIp; 103 } 104 105 public int getRemPort() { 106 return remPort; 107 } 108 109 @Override 110 public Asp createAsp() { 111 AspImpl remAsp = new AspImpl(this.name, this.m3UAProvider, this); 112 remAsp.setASPIdentifier(aspid); 113 this.aspList.add(remAsp); 114 return remAsp; 115 } 116 117 @Override 118 public void start() { 119 this.started = true; 120 } 121 122 @Override 123 public void stop() { 124 this.started = false; 125 126 if (this.channel != null) { 127 try { 128 this.channelConnected = this.channel.isConnected(); 129 } catch (IOException e1) { 130 logger.error(String.format("Error while checking if channel is connected for LocalAspfactory=%s", 131 this.name)); 132 } 133 } 134 135 if (this.channelConnected) { 136 ASPDown aspDown = (ASPDown) this.m3UAProvider.getMessageFactory().createMessage( 137 MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN); 138 this.write(aspDown); 139 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 140 Asp asp = n.getValue(); 141 142 try { 143 asp.getFSM().signal(TransitionState.ASP_DOWN_SENT); 144 As as = asp.getAs(); 145 as.aspStateChange(asp, TransitionState.ASP_DOWN); 146 } catch (UnknownTransitionException e) { 147 logger.error(e.getMessage(), e); 148 } 149 } 150 } else { 151 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 152 Asp asp = n.getValue(); 153 154 try { 155 asp.getFSM().signal(TransitionState.COMM_DOWN); 156 As as = asp.getAs(); 157 as.aspStateChange(asp, TransitionState.ASP_DOWN); 158 } catch (UnknownTransitionException e) { 159 logger.error(e.getMessage(), e); 160 } 161 } 162 } 163 } 164 165 @Override 166 public void read(M3UAMessage message) { 167 switch (message.getMessageClass()) { 168 case MessageClass.MANAGEMENT: 169 switch (message.getMessageType()) { 170 case MessageType.ERROR: 171 logger.error(message); 172 break; 173 case MessageType.NOTIFY: 174 Notify notify = (Notify) message; 175 this.handleNotify(notify); 176 break; 177 default: 178 logger.error(String.format("Received MGMT with invalid MessageType=%d message=%s", 179 message.getMessageType(), message)); 180 break; 181 } 182 break; 183 184 case MessageClass.TRANSFER_MESSAGES: 185 switch (message.getMessageType()) { 186 case MessageType.PAYLOAD: 187 PayloadData payload = (PayloadData) message; 188 this.handlePayload(payload); 189 break; 190 default: 191 logger.error(String.format("Received Transfer message with invalid MessageType=%d message=%s", 192 message.getMessageType(), message)); 193 break; 194 } 195 break; 196 197 case MessageClass.SIGNALING_NETWORK_MANAGEMENT: 198 switch (message.getMessageType()) { 199 case MessageType.DESTINATION_UNAVAILABLE: 200 DestinationUnavailable duna = (DestinationUnavailable) message; 201 this.handleDestinationUnavailable(duna); 202 break; 203 case MessageType.DESTINATION_AVAILABLE: 204 DestinationAvailable dava = (DestinationAvailable) message; 205 this.handleDestinationAvailable(dava); 206 break; 207 case MessageType.DESTINATION_STATE_AUDIT: 208 if (logger.isEnabledFor(Level.WARN)) { 209 logger.warn(String.format("Received DAUD message for AS side. This is error. Message=%s", message)); 210 } 211 break; 212 case MessageType.SIGNALING_CONGESTION: 213 SignallingCongestion scon = (SignallingCongestion) message; 214 this.handleSignallingCongestion(scon); 215 break; 216 case MessageType.DESTINATION_USER_PART_UNAVAILABLE: 217 DestinationUPUnavailable dupu = (DestinationUPUnavailable) message; 218 this.handleDestinationUPUnavailable(dupu); 219 break; 220 case MessageType.DESTINATION_RESTRICTED: 221 if (logger.isEnabledFor(Level.WARN)) { 222 logger.warn(String.format("Received DUPU message for AS side. Not implemented yet", message)); 223 } 224 break; 225 default: 226 logger.error(String.format("Received SSNM with invalid MessageType=%d message=%s", 227 message.getMessageType(), message)); 228 break; 229 } 230 break; 231 232 case MessageClass.ASP_STATE_MAINTENANCE: 233 switch (message.getMessageType()) { 234 case MessageType.ASP_UP_ACK: 235 ASPUpAck aspUpAck = (ASPUpAck) message; 236 this.handleAspUpAck(aspUpAck); 237 break; 238 case MessageType.ASP_DOWN_ACK: 239 ASPDownAck aspDownAck = (ASPDownAck) message; 240 this.handleAspDownAck(aspDownAck); 241 break; 242 case MessageType.HEARTBEAT: 243 Heartbeat hrtBeat = (Heartbeat) message; 244 this.handleHeartbeat(hrtBeat); 245 break; 246 default: 247 logger.error(String.format("Received ASPSM with invalid MessageType=%d message=%s", 248 message.getMessageType(), message)); 249 break; 250 } 251 252 break; 253 254 case MessageClass.ASP_TRAFFIC_MAINTENANCE: 255 switch (message.getMessageType()) { 256 case MessageType.ASP_ACTIVE_ACK: 257 ASPActiveAck aspAciveAck = (ASPActiveAck) message; 258 this.handleAspActiveAck(aspAciveAck); 259 break; 260 case MessageType.ASP_INACTIVE_ACK: 261 ASPInactiveAck aspInaciveAck = (ASPInactiveAck) message; 262 this.handleAspInactiveAck(aspInaciveAck); 263 break; 264 default: 265 logger.error(String.format("Received ASPTM with invalid MessageType=%d message=%s", 266 message.getMessageType(), message)); 267 break; 268 } 269 break; 270 271 case MessageClass.ROUTING_KEY_MANAGEMENT: 272 logger.error(String.format("Received %s. Handling of RKM message is not supported", message)); 273 break; 274 default: 275 logger.error(String.format("Received message with invalid MessageClass=%d message=%s", 276 message.getMessageClass(), message)); 277 break; 278 } 279 } 280 281 private void handleDestinationUPUnavailable(DestinationUPUnavailable dupu) { 282 RoutingContext rcObj = dupu.getRoutingContext(); 283 if (rcObj == null) { 284 logger.error(String.format("received DUPU but no RoutingContext carried in message. Message=%s", dupu)); 285 // TODO : If no RC defined, should send to all AS? 286 return; 287 } 288 289 long rc = rcObj.getRoutingContexts()[0]; 290 291 Asp asp = this.getAsp(rc); 292 293 if (asp == null) { 294 logger.error(String.format("received DUPU for RoutingContext=%d. But no ASP found. Message=%s", rc, dupu)); 295 // TODO : If no RC defined, should send to all AS? 296 return; 297 } 298 299 if (asp.getState() == AspState.ACTIVE) { 300 AffectedPointCode affectedPcObjs = dupu.getAffectedPointCode(); 301 int[] affectedPcs = affectedPcObjs.getPointCodes(); 302 303 int cause = 0; 304 for (int i = 0; i < affectedPcs.length; i++) { 305 306 UserCause userCause = dupu.getUserCause(); 307 cause = userCause.getCause(); 308 Mtp3StatusPrimitive mtpPausePrimi = new Mtp3StatusPrimitive(affectedPcs[i], 1, 0, cause); 309 asp.getAs().received(mtpPausePrimi); 310 } 311 } else { 312 logger.error(String.format("Received DUPU for RoutingContext=%d. But ASP State=%s. Message=%s", rc, 313 asp.getState(), dupu)); 314 } 315 316 } 317 318 private void handleSignallingCongestion(SignallingCongestion scon) { 319 RoutingContext rcObj = scon.getRoutingContexts(); 320 if (rcObj == null) { 321 logger.error(String.format("received SCON but no RoutingContext carried in message. Message=%s", scon)); 322 // TODO : If no RC defined, should send to all AS? 323 return; 324 } 325 326 long rc = rcObj.getRoutingContexts()[0]; 327 328 Asp asp = this.getAsp(rc); 329 330 if (asp == null) { 331 logger.error(String.format("received SCON for RoutingContext=%d. But no ASP found. Message=%s", rc, scon)); 332 // TODO : If no RC defined, should send to all AS? 333 return; 334 } 335 336 if (asp.getState() == AspState.ACTIVE) { 337 AffectedPointCode affectedPcObjs = scon.getAffectedPointCodes(); 338 int[] affectedPcs = affectedPcObjs.getPointCodes(); 339 340 int cong = 0; 341 for (int i = 0; i < affectedPcs.length; i++) { 342 CongestedIndication congeInd = scon.getCongestedIndication(); 343 if (congeInd != null) { 344 CongestionLevel congLevel = congeInd.getCongestionLevel(); 345 if (congLevel != null) { 346 cong = congLevel.getLevel(); 347 } 348 } 349 Mtp3StatusPrimitive mtpPausePrimi = new Mtp3StatusPrimitive(affectedPcs[i], 2, cong, 0); 350 asp.getAs().received(mtpPausePrimi); 351 } 352 } else { 353 logger.error(String.format("Received SCON for RoutingContext=%d. But ASP State=%s. Message=%s", rc, 354 asp.getState(), scon)); 355 } 356 357 } 358 359 private void handleDestinationUnavailable(DestinationUnavailable duna) { 360 RoutingContext rcObj = duna.getRoutingContexts(); 361 if (rcObj == null) { 362 logger.error(String.format("received DUNA but no RoutingContext carried in message. Message=%s", duna)); 363 // TODO : If no RC defined, should send to all AS? 364 return; 365 } 366 367 long rc = rcObj.getRoutingContexts()[0]; 368 369 Asp asp = this.getAsp(rc); 370 371 if (asp == null) { 372 logger.error(String.format("received DUNA for RoutingContext=%d. But no ASP found. Message=%s", rc, duna)); 373 // TODO : If no RC defined, should send to all AS? 374 return; 375 } 376 377 if (asp.getState() == AspState.ACTIVE) { 378 AffectedPointCode affectedPcObjs = duna.getAffectedPointCodes(); 379 int[] affectedPcs = affectedPcObjs.getPointCodes(); 380 381 for (int i = 0; i < affectedPcs.length; i++) { 382 Mtp3PausePrimitive mtpPausePrimi = new Mtp3PausePrimitive(affectedPcs[i]); 383 asp.getAs().received(mtpPausePrimi); 384 } 385 } else { 386 logger.error(String.format("Received DUNA for RoutingContext=%d. But ASP State=%s. Message=%s", rc, 387 asp.getState(), duna)); 388 } 389 } 390 391 private void handleDestinationAvailable(DestinationAvailable dava) { 392 RoutingContext rcObj = dava.getRoutingContexts(); 393 if (rcObj == null) { 394 logger.error(String.format("received DAVA but no RoutingContext carried in message. Message=%s", dava)); 395 // TODO : If no RC defined, should send to all AS? 396 return; 397 } 398 399 long rc = rcObj.getRoutingContexts()[0]; 400 401 Asp asp = this.getAsp(rc); 402 403 if (asp == null) { 404 logger.error(String.format("received DAVA for RoutingContext=%d. But no ASP found. Message=%s", rc, dava)); 405 // TODO : If no RC defined, should send to all AS? 406 return; 407 } 408 409 if (asp.getState() == AspState.ACTIVE) { 410 AffectedPointCode affectedPcObjs = dava.getAffectedPointCodes(); 411 int[] affectedPcs = affectedPcObjs.getPointCodes(); 412 for (int i = 0; i < affectedPcs.length; i++) { 413 Mtp3ResumePrimitive mtpResumePrimi = new Mtp3ResumePrimitive(affectedPcs[i]); 414 asp.getAs().received(mtpResumePrimi); 415 } 416 } else { 417 logger.error(String.format("Received DAVA for RoutingContext=%d. But ASP State=%s. Message=%s", rc, 418 asp.getState(), dava)); 419 } 420 } 421 422 private void handlePayload(PayloadData payload) { 423 // Payload is always for single AS 424 long rc = payload.getRoutingContext().getRoutingContexts()[0]; 425 Asp asp = this.getAsp(rc); 426 427 if (asp == null) { 428 logger.error(String.format("Rx : PayloadData for RoutingContext=%d. But no ASP found. Message=%s", rc, 429 payload)); 430 return; 431 } 432 433 if (asp.getState() == AspState.ACTIVE) { 434 asp.getAs().received(payload); 435 } else { 436 logger.error(String.format("Rx : PayloadData for RoutingContext=%d. But ASP State=%s. Message=%s", rc, 437 asp.getState(), payload)); 438 } 439 440 } 441 442 private void handleNotify(Notify notify) { 443 if (!this.started) { 444 // If management stopped this ASP, ignore Notify 445 return; 446 } 447 448 long[] rcs = notify.getRoutingContext().getRoutingContexts(); 449 for (int count = 0; count < rcs.length; count++) { 450 Asp asp = this.getAsp(rcs[count]); 451 try { 452 asp.getAs().aspStateChange(asp, TransitionState.getTransition(notify)); 453 } catch (UnknownTransitionException e) { 454 logger.error(e.getMessage(), e); 455 } 456 } 457 } 458 459 private void handleAspUpAck(ASPUpAck aspUpAck) { 460 if (!this.started) { 461 // If management stopped this ASP, ignore ASPUpAck 462 return; 463 } 464 465 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 466 Asp asp = n.getValue(); 467 boolean transToActive = this.activate(asp); 468 469 if (!transToActive) { 470 // Transition to INACTIVE 471 try { 472 asp.getFSM().signal(TransitionState.ASP_INACTIVE); 473 } catch (UnknownTransitionException e) { 474 logger.error(e.getMessage(), e); 475 } 476 } else { 477 // Transition to ACTIVE_SENT 478 try { 479 asp.getFSM().signal(TransitionState.ASP_ACTIVE_SENT); 480 } catch (UnknownTransitionException e) { 481 logger.error(e.getMessage(), e); 482 } 483 }// if..else 484 }// for 485 } 486 487 private void handleAspDownAck(ASPDownAck aspUpAck) { 488 489 if (!this.started) { 490 491 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 492 Asp asp = n.getValue(); 493 try { 494 asp.getFSM().signal(TransitionState.ASP_DOWN_ACK); 495 } catch (UnknownTransitionException e) { 496 logger.error(e.getMessage(), e); 497 } 498 } 499 500 // Close Channel if management stopped this 501 if (channel != null && this.channelConnected) { 502 try { 503 channel.close(); 504 if (logger.isDebugEnabled()) { 505 logger.debug(String.format("Closed the channel for LocalAspFactory name=%s", this.getName())); 506 } 507 } catch (IOException e) { 508 logger.error(String.format("IOException when trying to close channel for LocalAspFactory=%s", 509 this.name)); 510 } 511 } 512 } 513 } 514 515 private void handleHeartbeat(Heartbeat hrtBeat) { 516 HeartbeatAck hrtBeatAck = (HeartbeatAck) this.m3UAProvider.getMessageFactory().createMessage( 517 MessageClass.ASP_STATE_MAINTENANCE, MessageType.HEARTBEAT_ACK); 518 hrtBeatAck.setHeartbeatData(hrtBeat.getHeartbeatData()); 519 this.write(hrtBeatAck); 520 521 } 522 523 private void handleAspActiveAck(ASPActiveAck aspActiveAck) { 524 if (!this.started) { 525 // If management stopped this ASP, ignore ASPActiveAck 526 return; 527 } 528 529 TrafficModeType trMode = aspActiveAck.getTrafficModeType(); 530 531 long[] rcs = aspActiveAck.getRoutingContext().getRoutingContexts(); 532 for (int count = 0; count < rcs.length; count++) { 533 Asp asp = this.getAsp(rcs[count]); 534 asp.getAs().setTrafficModeType(trMode); 535 try { 536 asp.getFSM().signal(TransitionState.ASP_ACTIVE_ACK); 537 } catch (UnknownTransitionException e) { 538 logger.error(e.getMessage(), e); 539 } 540 } 541 } 542 543 private void handleAspInactiveAck(ASPInactiveAck aspInactiveAck) { 544 if (!this.started) { 545 // If management stopped this ASP, ignore ASPInactiveAck 546 return; 547 } 548 549 long[] rcs = aspInactiveAck.getRoutingContext().getRoutingContexts(); 550 for (int count = 0; count < rcs.length; count++) { 551 Asp asp = this.getAsp(rcs[count]); 552 try { 553 asp.getFSM().signal(TransitionState.ASP_INACTIVE_ACK); 554 } catch (UnknownTransitionException e) { 555 logger.error(e.getMessage(), e); 556 } 557 } 558 559 } 560 561 private void handleCommUp() { 562 this.channelConnected = true; 563 ASPUp aspUp = (ASPUp) this.m3UAProvider.getMessageFactory().createMessage(MessageClass.ASP_STATE_MAINTENANCE, 564 MessageType.ASP_UP); 565 aspUp.setASPIdentifier(this.aspid); 566 this.write(aspUp); 567 568 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 569 Asp asp = n.getValue(); 570 try { 571 asp.getFSM().signal(TransitionState.COMM_UP); 572 } catch (UnknownTransitionException e) { 573 logger.error(e.getMessage(), e); 574 } 575 } 576 } 577 578 private void handleCommDown() { 579 580 logger.warn(String.format("Communication channel down for LocalAspFactroy=%s", this.name)); 581 582 this.channelConnected = false; 583 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 584 Asp asp = n.getValue(); 585 try { 586 asp.getFSM().signal(TransitionState.COMM_DOWN); 587 asp.getAs().aspStateChange(asp, TransitionState.ASP_DOWN); 588 } catch (UnknownTransitionException e) { 589 logger.error(e.getMessage(), e); 590 } 591 } 592 593 if (this.channel != null) { 594 try { 595 this.channel.close(); 596 } catch (IOException e) { 597 logger.error(String.format("Error while closing channel for LocalAspFactory=%s", this.name)); 598 } 599 } 600 601 //If communication is down not because of management reason, try to bring it up again 602 if(this.started){ 603 this.m3uaManagement.startAsp(this); 604 } 605 } 606 607 protected boolean activate(Asp asp) { 608 // If its loadshare, we want to send ASP_ACTIVE else if its 609 // Override and there is already one ACTIVE, we leave this one 610 // as INACTIVE 611 612 As as = asp.getAs(); 613 614 // By default we assume Traffic Mode is Loadshare 615 if (as.getTrafficModeType() == null || as.getTrafficModeType().getMode() == TrafficModeType.Loadshare) { 616 // Activate this ASP 617 this.sendAspActive(as); 618 return true; 619 } else if (as.getTrafficModeType().getMode() == TrafficModeType.Override) { 620 621 for (FastList.Node<Asp> n = as.getAspList().head(), end = as.getAspList().tail(); (n = n.getNext()) != end;) { 622 Asp asptemp = n.getValue(); 623 if (asptemp.getName().compareTo(asp.getName()) != 0 624 && (asptemp.getState() == AspState.ACTIVE_SENT || asptemp.getState() == AspState.ACTIVE)) { 625 return false; 626 } 627 }// for 628 629 this.sendAspActive(as); 630 return true; 631 632 } 633 return false; 634 } 635 636 // Private Methods 637 protected void sendAspActive(As as) { 638 ASPActive aspActive = (ASPActive) this.m3UAProvider.getMessageFactory().createMessage( 639 MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE); 640 aspActive.setRoutingContext(as.getRoutingContext()); 641 aspActive.setTrafficModeType(as.getTrafficModeType()); 642 this.write(aspActive); 643 } 644 645 private Asp getAsp(long rc) { 646 for (FastList.Node<Asp> n = aspList.head(), end = aspList.tail(); (n = n.getNext()) != end;) { 647 Asp asp = n.getValue(); 648 if (asp.getAs().getRoutingContext().getRoutingContexts()[0] == rc) { 649 return asp; 650 } 651 } 652 return null; 653 } 654 655 public void onCommStateChange(CommunicationState state) { 656 switch (state) { 657 case UP: 658 this.handleCommUp(); 659 break; 660 case SHUTDOWN: 661 this.handleCommDown(); 662 break; 663 case LOST: 664 this.handleCommDown(); 665 break; 666 } 667 } 668 669 private long generateId() { 670 ASP_ID++; 671 if (ASP_ID == 4294967295l) { 672 ASP_ID = 1l; 673 } 674 return ASP_ID; 675 } 676 677 /** 678 * XML Serialization/Deserialization 679 */ 680 protected static final XMLFormat<LocalAspFactory> LOCAL_ASP_FACTORY_XML = new XMLFormat<LocalAspFactory>( 681 LocalAspFactory.class) { 682 683 @Override 684 public void read(javolution.xml.XMLFormat.InputElement xml, LocalAspFactory localAspFactory) 685 throws XMLStreamException { 686 ASP_FACTORY_XML.read(xml, localAspFactory); 687 localAspFactory.remIp = xml.getAttribute(REM_IP).toString(); 688 localAspFactory.remPort = xml.getAttribute(REM_PORT).toInt(); 689 // localAspFactory.channelConnected = 690 // xml.getAttribute(CHANNEL_CONNECTED).toBoolean(); 691 } 692 693 @Override 694 public void write(LocalAspFactory localAspFactory, javolution.xml.XMLFormat.OutputElement xml) 695 throws XMLStreamException { 696 ASP_FACTORY_XML.write(localAspFactory, xml); 697 xml.setAttribute(REM_IP, localAspFactory.remIp); 698 xml.setAttribute(REM_PORT, localAspFactory.remPort); 699 // xml.setAttribute(CHANNEL_CONNECTED, 700 // localAspFactory.channelConnected); 701 } 702 }; 703}