From 82f6766748cdbf895da22cefcb383db215ebbf76 Mon Sep 17 00:00:00 2001 From: Grzegorz Figiel Date: Mon, 16 Jan 2017 15:16:28 +0100 Subject: [PATCH] Fix for issue #9 - failover & load balancing --- .gitignore | 43 +++++--- .../diameter/base/events/DeliveryFailure.java | 63 ++++++++++++ .../base/events/DeliveryFailureImpl.java | 98 +++++++++++++++++++ .../en-US/ra-type/Section-Events.xml | 6 ++ .../src/main/resources/META-INF/event-jar.xml | 7 ++ resources/diameter-base/pom.xml | 4 +- .../diameter/cca/events/RequestTxTimeout.java | 73 ++++++++++++++ .../cca/events/RequestTxTimeoutImpl.java | 87 ++++++++++++++++ .../cca/handlers/DiameterExtRAInterface.java | 55 +++++++++++ .../src/main/resources/META-INF/event-jar.xml | 7 ++ .../META-INF/resource-adaptor-type-jar.xml | 6 ++ .../en-US/ra-type/Section-Events.xml | 16 ++- .../src/main/resources/META-INF/event-jar.xml | 10 +- .../ro/DiameterRoResourceAdaptor.java | 47 +++++++-- .../resource/diameter/ro/EventIDCache.java | 4 +- .../ro/handlers/RoSessionFactory.java | 20 +++- .../META-INF/resource-adaptor-type-jar.xml | 12 +++ .../ro/tests/factories/RoFactoriesTest.java | 17 +++- 18 files changed, 537 insertions(+), 38 deletions(-) create mode 100644 resources/diameter-base/common/events/src/main/java/net/java/slee/resource/diameter/base/events/DeliveryFailure.java create mode 100644 resources/diameter-base/common/events/src/main/java/org/mobicents/slee/resource/diameter/base/events/DeliveryFailureImpl.java create mode 100644 resources/diameter-cca/common/events/src/main/java/net/java/slee/resource/diameter/cca/events/RequestTxTimeout.java create mode 100644 resources/diameter-cca/common/events/src/main/java/org/mobicents/slee/resource/diameter/cca/events/RequestTxTimeoutImpl.java create mode 100644 resources/diameter-cca/common/ra/src/main/java/org/mobicents/slee/resource/diameter/cca/handlers/DiameterExtRAInterface.java diff --git a/.gitignore b/.gitignore index cdfed9175..c57e92307 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,47 @@ -# Java compiled # -################# +######## Java compiled ######### +################################ *.class -# Eclipse # -########### +########### Eclipse ############ +################################ .classpath .project .settings -# IntelliJ IDEA # -################# -.idea/ +######## IntelliJ IDEA ######### +################################ +.idea *.iml *.iws -# Maven # -######### +########## NetBeans ############ +################################ +nbactions.xml + +# Mobile Tools for Java (J2ME) # +################################ +.mtj.tmp + +############ Maven ############# +################################ target +*.jar +*.war +*.ear -# OS generated files # -###################### +###### OS generated files ###### +################################ +.directory +.Trashes +._* +*~ .DS_Store .DS_Store? -._* .Spotlight-V100 -.Trashes Icon? ehthumbs.db Thumbs.db + +######## VM crash logs ######### +################################ +hs_err_pid* diff --git a/resources/diameter-base/common/events/src/main/java/net/java/slee/resource/diameter/base/events/DeliveryFailure.java b/resources/diameter-base/common/events/src/main/java/net/java/slee/resource/diameter/base/events/DeliveryFailure.java new file mode 100644 index 000000000..154849a6f --- /dev/null +++ b/resources/diameter-base/common/events/src/main/java/net/java/slee/resource/diameter/base/events/DeliveryFailure.java @@ -0,0 +1,63 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package net.java.slee.resource.diameter.base.events; + +import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; + +import org.jdiameter.api.Message; +import org.jdiameter.api.RouteException; + +/** + * Event that represents delivery failure of a given message. + */ +public interface DeliveryFailure { + + /** + * Returns an exception that made delivery of a given message impossible. + * + * @return exception + */ + RouteException getCause(); + + /** + * Returns the request that caused Tx timeout to expire due to no response from a remote peer. + * + * @return origin request + */ + Message getRequest(); + + /** + * Returns the name of the last selected remote peer that a given message has been routed to. + * + * @return peer name + */ + DiameterIdentity getLastPeer(); + + /** + * Returns true if last selected remote peer is present for a given message. + * + * @return true if peer name is present + */ + boolean hasLastPeer(); + +} diff --git a/resources/diameter-base/common/events/src/main/java/org/mobicents/slee/resource/diameter/base/events/DeliveryFailureImpl.java b/resources/diameter-base/common/events/src/main/java/org/mobicents/slee/resource/diameter/base/events/DeliveryFailureImpl.java new file mode 100644 index 000000000..79d6a2d4a --- /dev/null +++ b/resources/diameter-base/common/events/src/main/java/org/mobicents/slee/resource/diameter/base/events/DeliveryFailureImpl.java @@ -0,0 +1,98 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.slee.resource.diameter.base.events; + +import net.java.slee.resource.diameter.base.events.DeliveryFailure; +import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; + +import org.jdiameter.api.Message; +import org.jdiameter.api.RouteException; + +/** + * Delivery failure implementation. + */ +public class DeliveryFailureImpl implements DeliveryFailure { + + protected RouteException cause = null; + protected Message request = null; + protected DiameterIdentity peer = null; + + /** + * Constructor. + * @param request + * @param peer + */ + public DeliveryFailureImpl(RouteException cause, Message request, DiameterIdentity peer) { + this.cause = cause; + this.request = request; + this.peer = peer; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.base.events.DeliveryFailure#getCause() + */ + public RouteException getCause() { + return cause; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.base.events.DeliveryFailure#getRequest() + */ + public Message getRequest() { + return request; + } + + /* + * (non-Javadoc) + * @see nnet.java.slee.resource.diameter.base.events.DeliveryFailure#getLastPeer() + */ + public DiameterIdentity getLastPeer() { + return peer; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.base.events.DeliveryFailure#hasLastPeer() + */ + public boolean hasLastPeer() { + return peer != null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("\r\n"); + sb.append("+--------------------------- Delivery failure ---------------------------------+\r\n"); + sb.append("| Last selected peer: ").append(peer).append("\r\n"); + sb.append("| Failure for message: ").append(request).append("\r\n"); + sb.append("| Application-Id..........").append(request.getApplicationId()).append("\r\n"); + sb.append("| Hop-By-Hop Identifier...").append(request.getHopByHopIdentifier()).append("\r\n"); + sb.append("| End-To-End Identifier...").append(request.getEndToEndIdentifier()).append("\r\n"); + sb.append("| Session-Id..............").append(request.getSessionId()).append("\r\n"); + sb.append("| Root cause: ").append(cause).append("\r\n"); + sb.append("+-----------------------------------------------------------------------------+\r\n"); + return sb.toString(); + } +} diff --git a/resources/diameter-base/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml b/resources/diameter-base/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml index 3c610b358..2d431c933 100644 --- a/resources/diameter-base/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml +++ b/resources/diameter-base/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml @@ -186,6 +186,12 @@ 0.8 net.java.slee.resource. diameter.base.events. ErrorAnswer + + net.java.slee.resource. diameter.base.events. DeliveryFailure + java.net + 0.8 + net.java.slee.resource. diameter.base.events. DeliveryFailure + diff --git a/resources/diameter-base/events/src/main/resources/META-INF/event-jar.xml b/resources/diameter-base/events/src/main/resources/META-INF/event-jar.xml index c38df8d8d..3b6ae747b 100644 --- a/resources/diameter-base/events/src/main/resources/META-INF/event-jar.xml +++ b/resources/diameter-base/events/src/main/resources/META-INF/event-jar.xml @@ -111,6 +111,13 @@ net.java.slee.resource.diameter.base.events.SessionTerminationAnswer + + net.java.slee.resource.diameter.base.events.DeliveryFailure + java.net + 0.8 + net.java.slee.resource.diameter.base.events.DeliveryFailure + + net.java.slee.resource.diameter.base.events.ErrorAnswer java.net diff --git a/resources/diameter-base/pom.xml b/resources/diameter-base/pom.xml index a653b5274..fb2bcbc82 100644 --- a/resources/diameter-base/pom.xml +++ b/resources/diameter-base/pom.xml @@ -26,8 +26,8 @@ - 1.7.0.77 - 1.7.0.77 + 1.7.0-SNAPSHOT + 1.7.0-SNAPSHOT 2.8.26 restcomm diff --git a/resources/diameter-cca/common/events/src/main/java/net/java/slee/resource/diameter/cca/events/RequestTxTimeout.java b/resources/diameter-cca/common/events/src/main/java/net/java/slee/resource/diameter/cca/events/RequestTxTimeout.java new file mode 100644 index 000000000..a67f7b2f0 --- /dev/null +++ b/resources/diameter-cca/common/events/src/main/java/net/java/slee/resource/diameter/cca/events/RequestTxTimeout.java @@ -0,0 +1,73 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package net.java.slee.resource.diameter.cca.events; + +import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; + +import org.jdiameter.api.Message; + +/** + * Tx timer as specified in RFC 4006: + * + *
+ * 13.  Credit-Control Application Related Parameters
+ *   
+ *  Tx timer
+ *   
+ *   When real-time credit-control is required, the credit-control
+ *   client contacts the credit-control server before and while the
+ *   service is provided to an end user. Due to the real-time nature
+ *   of the application, the communication delays SHOULD be minimized;
+ *   e.g., to avoid an overly long service setup time experienced by
+ *   the end user. The Tx timer is introduced to control the waiting
+ *   time in the client in the Pending state. When the Tx timer
+ *   elapses, the credit-control client takes an action to the end user
+ *   according to the value of the Credit-Control-Failure-Handling AVP
+ *   or Direct-Debiting-Failure-Handling AVP. The recommended value is
+ *   10 seconds.
+ * 
+ */ +public interface RequestTxTimeout { + + /** + * Returns the request that caused Tx timeout to expire due to no response from a remote peer. + * + * @return origin request + */ + Message getRequest(); + + /** + * Returns the name of the last selected remote peer that a given message has been routed to. + * + * @return peer name + */ + DiameterIdentity getLastPeer(); + + /** + * Returns true if last selected remote peer is present for a given message. + * + * @return true if peer name is present + */ + boolean hasLastPeer(); + +} diff --git a/resources/diameter-cca/common/events/src/main/java/org/mobicents/slee/resource/diameter/cca/events/RequestTxTimeoutImpl.java b/resources/diameter-cca/common/events/src/main/java/org/mobicents/slee/resource/diameter/cca/events/RequestTxTimeoutImpl.java new file mode 100644 index 000000000..bbcf94330 --- /dev/null +++ b/resources/diameter-cca/common/events/src/main/java/org/mobicents/slee/resource/diameter/cca/events/RequestTxTimeoutImpl.java @@ -0,0 +1,87 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.slee.resource.diameter.cca.events; + +import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; +import net.java.slee.resource.diameter.cca.events.RequestTxTimeout; + +import org.jdiameter.api.Avp; +import org.jdiameter.api.Message; + +/** + * Tx timer implementation. + */ +public class RequestTxTimeoutImpl implements RequestTxTimeout { + + protected Message request = null; + protected DiameterIdentity peer = null; + + /** + * Constructor. + * @param request + * @param peer + */ + public RequestTxTimeoutImpl(Message request, DiameterIdentity peer) { + this.request = request; + this.peer = peer; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.cca.events.RequestTxTimeout#getRequest() + */ + public Message getRequest() { + return request; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.cca.events.RequestTxTimeout#getLastPeer() + */ + public DiameterIdentity getLastPeer() { + return peer; + } + + /* + * (non-Javadoc) + * @see net.java.slee.resource.diameter.cca.events.RequestTxTimeout#hasLastPeer() + */ + public boolean hasLastPeer() { + return peer != null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("\r\n"); + sb.append("+--------------------------- Request timeout ---------------------------------+\r\n"); + sb.append("| Last selected peer: ").append(peer).append("\r\n"); + sb.append("| Timeout for message: ").append(request).append("\r\n"); + sb.append("| Application-Id..........").append(request.getApplicationId()).append("\r\n"); + sb.append("| Hop-By-Hop Identifier...").append(request.getHopByHopIdentifier()).append("\r\n"); + sb.append("| End-To-End Identifier...").append(request.getEndToEndIdentifier()).append("\r\n"); + sb.append("| Session-Id..............").append(request.getSessionId()).append("\r\n"); + sb.append("+-----------------------------------------------------------------------------+\r\n"); + return sb.toString(); + } +} diff --git a/resources/diameter-cca/common/ra/src/main/java/org/mobicents/slee/resource/diameter/cca/handlers/DiameterExtRAInterface.java b/resources/diameter-cca/common/ra/src/main/java/org/mobicents/slee/resource/diameter/cca/handlers/DiameterExtRAInterface.java new file mode 100644 index 000000000..1a35602df --- /dev/null +++ b/resources/diameter-cca/common/ra/src/main/java/org/mobicents/slee/resource/diameter/cca/handlers/DiameterExtRAInterface.java @@ -0,0 +1,55 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.mobicents.slee.resource.diameter.cca.handlers; + +import org.jdiameter.api.Message; +import org.jdiameter.api.Peer; +import org.jdiameter.api.RouteException; +import org.jdiameter.api.ro.ClientRoSession; +import org.jdiameter.api.ro.events.RoCreditControlRequest; +import org.mobicents.slee.resource.diameter.base.handlers.DiameterRAInterface; + +/** + * This should be implemented by RA. + */ +public interface DiameterExtRAInterface extends DiameterRAInterface { + + /** + * Makes RA fire timeout event. + * + * @param sessionId + * @param message + * @param peer + */ + public void fireTimeout(String sessionId, Message message, Peer peer); + + /** + * Makes RA fire delivery failure event. + * + * @param cause + * @param sessionId + * @param message + * @param peer + */ + public void fireDeliveryFailure(RouteException cause, String session, Message msg, Peer peer); +} diff --git a/resources/diameter-cca/events/src/main/resources/META-INF/event-jar.xml b/resources/diameter-cca/events/src/main/resources/META-INF/event-jar.xml index 463293bdf..20d19e120 100644 --- a/resources/diameter-cca/events/src/main/resources/META-INF/event-jar.xml +++ b/resources/diameter-cca/events/src/main/resources/META-INF/event-jar.xml @@ -24,4 +24,11 @@ net.java.slee.resource.diameter.cca.events.CreditControlAnswer
+ + net.java.slee.resource.diameter.cca.events.RequestTxTimeout + java.net + 0.8 + net.java.slee.resource.diameter.cca.events.RequestTxTimeout + + diff --git a/resources/diameter-cca/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml b/resources/diameter-cca/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml index b70b6f6a6..87b8fddd6 100644 --- a/resources/diameter-cca/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml +++ b/resources/diameter-cca/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml @@ -48,6 +48,12 @@ java.net 0.8 + + + net.java.slee.resource.diameter.cca.events.RequestTxTimeout + java.net + 0.8 + net.java.slee.resource.diameter.base.events.ReAuthRequest diff --git a/resources/diameter-ro/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml b/resources/diameter-ro/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml index b24579267..28f1d9b4a 100644 --- a/resources/diameter-ro/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml +++ b/resources/diameter-ro/docs/sources/src/main/resources/en-US/ra-type/Section-Events.xml @@ -29,10 +29,10 @@ - net.java.slee.resource. diameter.cca.events. CreditControlRequest + net.java.slee.resource. diameter.ro.events. RoCreditControlRequest java.net 0.8 - net.java.slee.resource. diameter.cca.events. CreditControlRequest + net.java.slee.resource. diameter.ro.events. RoCreditControlRequest @@ -54,11 +54,17 @@ - net.java.slee.resource. diameter.cca.events. CreditControlAnswer + net.java.slee.resource. diameter.ro.events. RoCreditControlAnswer java.net 0.8 - net.java.slee.resource. diameter.cca.events. CreditControlAnswer - + net.java.slee.resource. diameter.ro.events. RoCreditControlAnswer + + + net.java.slee.resource. diameter.ro.events. RequestTxTimeout + java.net + 0.8 + net.java.slee.resource. diameter.cca.events. RequestTxTimeout + diff --git a/resources/diameter-ro/events/src/main/resources/META-INF/event-jar.xml b/resources/diameter-ro/events/src/main/resources/META-INF/event-jar.xml index 0a0110baf..59da1447d 100644 --- a/resources/diameter-ro/events/src/main/resources/META-INF/event-jar.xml +++ b/resources/diameter-ro/events/src/main/resources/META-INF/event-jar.xml @@ -1,5 +1,5 @@ - + @@ -9,6 +9,7 @@ java.net 1.0 + net.java.slee.resource.diameter.ro.events.RoCreditControlRequest java.net @@ -23,4 +24,11 @@ net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer + + net.java.slee.resource.diameter.ro.events.RequestTxTimeout + java.net + 0.8 + net.java.slee.resource.diameter.cca.events.RequestTxTimeout + + diff --git a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/DiameterRoResourceAdaptor.java b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/DiameterRoResourceAdaptor.java index f179a76b3..bee49fe9a 100644 --- a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/DiameterRoResourceAdaptor.java +++ b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/DiameterRoResourceAdaptor.java @@ -51,10 +51,12 @@ import net.java.slee.resource.diameter.base.DiameterException; import net.java.slee.resource.diameter.base.events.AbortSessionAnswer; import net.java.slee.resource.diameter.base.events.AccountingAnswer; +import net.java.slee.resource.diameter.base.events.DeliveryFailure; import net.java.slee.resource.diameter.base.events.DiameterMessage; import net.java.slee.resource.diameter.base.events.ReAuthAnswer; import net.java.slee.resource.diameter.base.events.SessionTerminationAnswer; import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; +import net.java.slee.resource.diameter.cca.events.RequestTxTimeout; import net.java.slee.resource.diameter.ro.RoAvpFactory; import net.java.slee.resource.diameter.ro.RoClientSessionActivity; import net.java.slee.resource.diameter.ro.RoMessageFactory; @@ -73,6 +75,7 @@ import org.jdiameter.api.Peer; import org.jdiameter.api.PeerTable; import org.jdiameter.api.Request; +import org.jdiameter.api.RouteException; import org.jdiameter.api.Session; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.Stack; @@ -97,6 +100,7 @@ import org.mobicents.slee.resource.diameter.base.events.AbortSessionRequestImpl; import org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl; import org.mobicents.slee.resource.diameter.base.events.AccountingRequestImpl; +import org.mobicents.slee.resource.diameter.base.events.DeliveryFailureImpl; import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl; import org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl; import org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl; @@ -105,6 +109,8 @@ import org.mobicents.slee.resource.diameter.base.events.SessionTerminationAnswerImpl; import org.mobicents.slee.resource.diameter.base.events.SessionTerminationRequestImpl; import org.mobicents.slee.resource.diameter.base.handlers.DiameterRAInterface; +import org.mobicents.slee.resource.diameter.cca.events.RequestTxTimeoutImpl; +import org.mobicents.slee.resource.diameter.cca.handlers.DiameterExtRAInterface; import org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl; import org.mobicents.slee.resource.diameter.ro.events.RoCreditControlRequestImpl; import org.mobicents.slee.resource.diameter.ro.handlers.RoSessionFactory; @@ -114,7 +120,7 @@ * * @author Alexandre Mendonca */ -public class DiameterRoResourceAdaptor implements ResourceAdaptor, DiameterListener, DiameterRAInterface ,org.mobicents.slee.resource.cluster.FaultTolerantResourceAdaptor { +public class DiameterRoResourceAdaptor implements ResourceAdaptor, DiameterListener, DiameterExtRAInterface ,org.mobicents.slee.resource.cluster.FaultTolerantResourceAdaptor { private static final long serialVersionUID = 1L; @@ -180,7 +186,7 @@ public class DiameterRoResourceAdaptor implements ResourceAdaptor, DiameterListe // Default Failure Handling protected int defaultDirectDebitingFailureHandling = 0; - protected int defaultCreditControlFailureHandling = 0; + protected int defaultCreditControlFailureHandling = 1; // Validity and TxTimer values (in seconds) protected long defaultValidityTime = 30; @@ -588,16 +594,16 @@ public void activityUnreferenced(ActivityHandle handle) { // Event and Activities management ------------------------------------- - public boolean fireEvent(Object event, ActivityHandle handle, FireableEventType eventID, Address address, boolean useFiltering, boolean transacted) { + public boolean fireEvent(Object event, ActivityHandle handle, FireableEventType eventID, Address address, boolean useFiltering) { - if (useFiltering && eventIDFilter.filterEvent(eventID)) { + if (eventID == null) { + tracer.severe("Event ID for " + eventID + " is unknown, unable to fire."); + } + else if (useFiltering && eventIDFilter.filterEvent(eventID)) { if (tracer.isFineEnabled()) { tracer.fine("Event " + eventID + " filtered"); } } - else if (eventID == null) { - tracer.severe("Event ID for " + eventID + " is unknown, unable to fire."); - } else { if (tracer.isFineEnabled()) { tracer.fine("Firing event " + event + " on handle " + handle); @@ -632,9 +638,31 @@ public void fireEvent(String sessionId, Message message) { FireableEventType eventId = eventIdCache.getEventId(eventLookup, message); - this.fireEvent(event, getActivityHandle(sessionId), eventId, null, true, message.isRequest()); + this.fireEvent(event, getActivityHandle(sessionId), eventId, null, true); } - + + /* + * (non-Javadoc) + * @see org.mobicents.slee.resource.diameter.cca.handlers.DiameterExtRAInterface#fireTimeout(java.lang.String sessionId, org.jdiameter.api.Message message, org.jdiameter.api.Peer peer) + */ + public void fireTimeout(String sessionId, Message message, Peer peer) { + RequestTxTimeout event = new RequestTxTimeoutImpl(message, + peer != null ? new DiameterIdentity(peer.getUri().toString()) : null); + FireableEventType eventId = eventIdCache.getEventId(eventLookup, EventIDCache.REQUEST_TIMEOUT); + this.fireEvent(event, getActivityHandle(sessionId), eventId, null, true); + } + + /* + * (non-Javadoc) + * @see org.mobicents.slee.resource.diameter.cca.handlers.DiameterExtRAInterface#fireDeliveryFailure(org.jdiameter.api.RouteException cause, java.lang.String sessionId, org.jdiameter.api.Message message, org.jdiameter.api.Peer peer) + */ + public void fireDeliveryFailure(RouteException cause, String sessionId, Message message, Peer peer) { + DeliveryFailure event = new DeliveryFailureImpl(cause, message, + peer != null ? new DiameterIdentity(peer.getUri().toString()) : null); + FireableEventType eventId = eventIdCache.getEventId(eventLookup, EventIDCache.DELIVERY_FAILURE); + this.fireEvent(event, getActivityHandle(sessionId), eventId, null, true); + } + /** * {@inheritDoc} */ @@ -1212,5 +1240,4 @@ public DiameterIdentity[] getConnectedPeers() { return new DiameterIdentity[0]; } - } diff --git a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/EventIDCache.java b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/EventIDCache.java index 55e6133a4..b50af0216 100644 --- a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/EventIDCache.java +++ b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/EventIDCache.java @@ -74,8 +74,10 @@ public class EventIDCache { eventNames = Collections.unmodifiableMap(eventsTemp); } + public static final String DELIVERY_FAILURE = BASE_PACKAGE_PREFIX + "DeliveryFailure"; public static final String ERROR_ANSWER = BASE_PACKAGE_PREFIX + "ErrorAnswer"; public static final String EXTENSION_DIAMETER_MESSAGE = BASE_PACKAGE_PREFIX + "ExtensionDiameterMessage"; + public static final String REQUEST_TIMEOUT = RO_PACKAGE_PREFIX + "RequestTxTimeout"; private static final String VENDOR = "java.net"; private static final String VERSION = "0.8"; @@ -122,7 +124,7 @@ public FireableEventType getEventId(EventLookupFacility eventLookupFacility, Mes * @param eventName * @return */ - private FireableEventType getEventId(EventLookupFacility eventLookupFacility, String eventName) { + public FireableEventType getEventId(EventLookupFacility eventLookupFacility, String eventName) { FireableEventType eventType = eventIds.get(eventName); if (eventType == null) { diff --git a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/handlers/RoSessionFactory.java b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/handlers/RoSessionFactory.java index 72b29bac7..0b4aa8ee0 100644 --- a/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/handlers/RoSessionFactory.java +++ b/resources/diameter-ro/ra/src/main/java/org/mobicents/slee/resource/diameter/ro/handlers/RoSessionFactory.java @@ -23,6 +23,9 @@ package org.mobicents.slee.resource.diameter.ro.handlers; import org.jdiameter.api.InternalException; +import org.jdiameter.api.Message; +import org.jdiameter.api.Peer; +import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; @@ -34,7 +37,7 @@ import org.jdiameter.api.ro.events.RoCreditControlAnswer; import org.jdiameter.api.ro.events.RoCreditControlRequest; import org.jdiameter.common.impl.app.ro.RoSessionFactoryImpl; -import org.mobicents.slee.resource.diameter.base.handlers.DiameterRAInterface; +import org.mobicents.slee.resource.diameter.cca.handlers.DiameterExtRAInterface; /** * @@ -43,12 +46,12 @@ */ public class RoSessionFactory extends RoSessionFactoryImpl { - public DiameterRAInterface ra; + public DiameterExtRAInterface ra; /** * @param sessionFactory */ - public RoSessionFactory(DiameterRAInterface ra, SessionFactory sessionFactory, int defaultDirectDebitingFailureHandling, int defaultCreditControlFailureHandling, long defaultValidityTime, long defaultTxTimerValue) { + public RoSessionFactory(DiameterExtRAInterface ra, SessionFactory sessionFactory, int defaultDirectDebitingFailureHandling, int defaultCreditControlFailureHandling, long defaultValidityTime, long defaultTxTimerValue) { super(sessionFactory); super.defaultDirectDebitingFailureHandling = defaultDirectDebitingFailureHandling; @@ -83,5 +86,14 @@ public void doReAuthAnswer(ServerRoSession session, ReAuthRequest request, ReAut public void doReAuthRequest(ClientRoSession session, ReAuthRequest request) throws InternalException { ra.fireEvent(session.getSessionId(), request.getMessage()); } - + + @Override + public void doRequestTimeout(ClientRoSession session, Message msg, Peer peer) throws InternalException { + ra.fireTimeout(session.getSessionId(), msg, peer); + } + + @Override + public void doPeerUnavailability(RouteException cause, ClientRoSession session, Message msg, Peer peer) throws InternalException { + ra.fireDeliveryFailure(cause, session.getSessionId(), msg, peer); + } } diff --git a/resources/diameter-ro/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml b/resources/diameter-ro/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml index 4ea109c32..fe6247dcb 100644 --- a/resources/diameter-ro/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml +++ b/resources/diameter-ro/ratype/src/main/resources/META-INF/resource-adaptor-type-jar.xml @@ -47,6 +47,12 @@ java.net 0.8 + + + net.java.slee.resource.diameter.ro.events.RequestTxTimeout + java.net + 0.8 + net.java.slee.resource.diameter.base.events.ReAuthRequest @@ -72,6 +78,12 @@ 0.8 + + net.java.slee.resource.diameter.base.events.DeliveryFailure + java.net + 0.8 + + net.java.slee.resource.diameter.base.events.ErrorAnswer diff --git a/resources/diameter-ro/testsuite/src/test/java/org/mobicents/slee/resource/diameter/ro/tests/factories/RoFactoriesTest.java b/resources/diameter-ro/testsuite/src/test/java/org/mobicents/slee/resource/diameter/ro/tests/factories/RoFactoriesTest.java index ac68a121a..f0fdd37ac 100644 --- a/resources/diameter-ro/testsuite/src/test/java/org/mobicents/slee/resource/diameter/ro/tests/factories/RoFactoriesTest.java +++ b/resources/diameter-ro/testsuite/src/test/java/org/mobicents/slee/resource/diameter/ro/tests/factories/RoFactoriesTest.java @@ -22,7 +22,10 @@ package org.mobicents.slee.resource.diameter.ro.tests.factories; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity; import net.java.slee.resource.diameter.cca.events.avp.CcRequestType; import net.java.slee.resource.diameter.ro.RoAvpFactory; @@ -36,7 +39,9 @@ import org.jdiameter.api.ApplicationId; import org.jdiameter.api.IllegalDiameterStateException; import org.jdiameter.api.InternalException; +import org.jdiameter.api.Message; import org.jdiameter.api.OverloadException; +import org.jdiameter.api.Peer; import org.jdiameter.api.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.Stack; @@ -116,7 +121,7 @@ public class RoFactoriesTest implements IRoMessageFactory, ServerRoSessionListen public RoFactoriesTest() { try { serverSession = new ServerRoSessionImpl(new ServerRoSessionDataLocalImpl(), this, (ISessionFactory) stack.getSessionFactory(), this, null, null); - clientSession = new ClientRoSessionImpl(new ClientRoSessionDataLocalImpl(), this, (ISessionFactory) stack.getSessionFactory(), this, null, null); + clientSession = new ClientRoSessionImpl(new ClientRoSessionDataLocalImpl(), this, null, (ISessionFactory) stack.getSessionFactory(), this, null, null); roServerSession = new RoServerSessionActivityImpl(roMessageFactory, roAvpFactory, serverSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack); roClientSession = new RoClientSessionActivityImpl(roMessageFactory, roAvpFactory, clientSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), @@ -354,6 +359,14 @@ public void doReAuthRequest(ClientRoSession session, ReAuthRequest request) thro // NO-OP } + public void doRequestTimeout(ClientRoSession session, Message msg, Peer peer) throws InternalException { + // NO-OP + } + + public void doPeerUnavailability(RouteException cause, ClientRoSession session, Message msg, Peer peer) throws InternalException { + // NO-OP + } + public int getDefaultDDFHValue() { // NO-OP return 0;