code
stringlengths
3
1.18M
language
stringclasses
1 value
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JPushProfileAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JPushProfileAnswerImpl extends AppAnswerEventImpl implements JPushProfileAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JPushProfileAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JPushProfileAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JPushProfileAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JPushProfileAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Message; import org.jdiameter.api.cxdx.events.JLocationInfoRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JLocationInfoRequestImpl extends AppRequestEventImpl implements JLocationInfoRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JLocationInfoRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JServerAssignmentAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JServerAssignmentAnswerImpl extends AppAnswerEventImpl implements JServerAssignmentAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JServerAssignmentAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JServerAssignmentAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JServerAssignmentAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JServerAssignmentAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JMultimediaAuthAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JMultimediaAuthAnswerImpl extends AppAnswerEventImpl implements JMultimediaAuthAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JMultimediaAuthAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JMultimediaAuthAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JMultimediaAuthAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JMultimediaAuthAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JRegistrationTerminationAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JRegistrationTerminationAnswerImpl extends AppAnswerEventImpl implements JRegistrationTerminationAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JRegistrationTerminationAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JRegistrationTerminationAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JRegistrationTerminationAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JRegistrationTerminationAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Message; import org.jdiameter.api.cxdx.events.JUserAuthorizationRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JUserAuthorizationRequestImpl extends AppRequestEventImpl implements JUserAuthorizationRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JUserAuthorizationRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Message; import org.jdiameter.api.cxdx.events.JPushProfileRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JPushProfileRequestImpl extends AppRequestEventImpl implements JPushProfileRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JPushProfileRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import java.io.Serializable; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.app.StateMachine; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.cxdx.ICxDxMessageFactory; import org.jdiameter.common.api.app.cxdx.ICxDxSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public abstract class CxDxSession extends AppSessionImpl implements NetworkReqListener, StateMachine { public static final int _TX_TIMEOUT = 30 * 1000; protected Lock sendAndStateLock = new ReentrantLock(); protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); protected transient ICxDxMessageFactory messageFactory; //protected CxDxSessionState state = CxDxSessionState.IDLE; // protected Future timeoutTaskFuture; // this can be weird //protected Serializable timerId_timeout; protected static final String TIMER_NAME_MSG_TIMEOUT = "MSG_TIMEOUT"; //protected Message buffer; protected ICxDxSessionData sessionData; public CxDxSession(ISessionFactory sf, ICxDxSessionData sessionData) { super(sf, sessionData); this.sessionData = sessionData; } @SuppressWarnings("unchecked") public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } @SuppressWarnings("unchecked") public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public boolean isStateless() { // Cx/Dx is always stateless return true; } /* (non-Javadoc) * @see org.jdiameter.common.impl.app.AppSessionImpl#isReplicable() */ @Override public boolean isReplicable() { // Cx/Dx is event based.. return false; } @Override public void release() { //stateListeners.clear(); super.release(); } protected void startMsgTimer() { try { sendAndStateLock.lock(); sessionData.setTsTimerId(super.timerFacility.schedule(getSessionId(), TIMER_NAME_MSG_TIMEOUT, _TX_TIMEOUT)); } finally { sendAndStateLock.unlock(); } } protected void cancelMsgTimer() { try { sendAndStateLock.lock(); final Serializable timerId = this.sessionData.getTsTimerId(); if(timerId == null) { return; } super.timerFacility.cancel(timerId); this.sessionData.setTsTimerId(null); } finally { sendAndStateLock.unlock(); } } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((sessionData == null) ? 0 : sessionData.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CxDxSession other = (CxDxSession) obj; if (sessionData == null) { if (other.sessionData != null) return false; } else if (!sessionData.equals(other.sessionData)) return false; return true; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Message; import org.jdiameter.api.cxdx.events.JRegistrationTerminationRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JRegistrationTerminationRequestImpl extends AppRequestEventImpl implements JRegistrationTerminationRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JRegistrationTerminationRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JLocationInfoAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JLocationInfoAnswerImpl extends AppAnswerEventImpl implements JLocationInfoAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JLocationInfoAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JLocationInfoAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JLocationInfoAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JLocationInfoAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.cxdx.ClientCxDxSession; import org.jdiameter.api.cxdx.ServerCxDxSession; import org.jdiameter.client.impl.app.cxdx.ClientCxDxSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.cxdx.ICxDxSessionData; import org.jdiameter.server.impl.app.cxdx.ServerCxDxSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class CxDxLocalSessionDataFactory implements IAppSessionDataFactory<ICxDxSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public ICxDxSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientCxDxSession.class)) { ClientCxDxSessionDataLocalImpl data = new ClientCxDxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerCxDxSession.class)) { ServerCxDxSessionDataLocalImpl data = new ServerCxDxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.cxdx.events.JUserAuthorizationAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JUserAuthorizationAnswerImpl extends AppAnswerEventImpl implements JUserAuthorizationAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public JUserAuthorizationAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public JUserAuthorizationAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public JUserAuthorizationAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public JUserAuthorizationAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2009, 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.jdiameter.common.impl.app.cxdx; import org.jdiameter.api.Message; import org.jdiameter.api.cxdx.events.JMultimediaAuthRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JMultimediaAuthRequestImpl extends AppRequestEventImpl implements JMultimediaAuthRequest{ private static final long serialVersionUID = 1L; /** * * @param message */ public JMultimediaAuthRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JDeleteSubscriberDataAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JDeleteSubscriberDataAnswerImpl extends AppAnswerEventImpl implements JDeleteSubscriberDataAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JDeleteSubscriberDataAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JDeleteSubscriberDataAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JPurgeUERequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JPurgeUERequestImpl extends AppRequestEventImpl implements JPurgeUERequest{ private static final long serialVersionUID = 1L; /** * * @param message */ public JPurgeUERequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JPurgeUEAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JPurgeUEAnswerImpl extends AppAnswerEventImpl implements JPurgeUEAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JPurgeUEAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JPurgeUEAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.s6a.ClientS6aSession; import org.jdiameter.api.s6a.ServerS6aSession; import org.jdiameter.client.impl.app.s6a.ClientS6aSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.s6a.IS6aSessionData; import org.jdiameter.server.impl.app.s6a.ServerS6aSessionDataLocalImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class S6aLocalSessionDataFactory implements IAppSessionDataFactory<IS6aSessionData>{ /* * (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ public IS6aSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientS6aSession.class)) { ClientS6aSessionDataLocalImpl data = new ClientS6aSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerS6aSession.class)) { ServerS6aSessionDataLocalImpl data = new ServerS6aSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else { throw new IllegalArgumentException("Invalid Session Class: " + clazz.toString()); } } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JResetRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JResetRequestImpl extends AppRequestEventImpl implements JResetRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JResetRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JNotifyAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JNotifyAnswerImpl extends AppAnswerEventImpl implements JNotifyAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JNotifyAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JNotifyAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import java.io.Serializable; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.app.StateMachine; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.s6a.IS6aMessageFactory; import org.jdiameter.common.api.app.s6a.IS6aSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public abstract class S6aSession extends AppSessionImpl implements NetworkReqListener, StateMachine { public static final int _TX_TIMEOUT = 30 * 1000; protected Lock sendAndStateLock = new ReentrantLock(); protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); protected transient IS6aMessageFactory messageFactory; protected static final String TIMER_NAME_MSG_TIMEOUT = "MSG_TIMEOUT"; protected IS6aSessionData sessionData; public S6aSession(ISessionFactory sf, IS6aSessionData sessionData) { super(sf, sessionData); this.sessionData = sessionData; } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public boolean isStateless() { return true; } @Override public boolean isReplicable() { return false; } protected void startMsgTimer() { try { sendAndStateLock.lock(); sessionData.setTsTimerId(super.timerFacility.schedule(getSessionId(), TIMER_NAME_MSG_TIMEOUT, _TX_TIMEOUT)); } finally { sendAndStateLock.unlock(); } } protected void cancelMsgTimer() { try { sendAndStateLock.lock(); final Serializable timerId = this.sessionData.getTsTimerId(); if(timerId == null) { return; } super.timerFacility.cancel(timerId); this.sessionData.setTsTimerId(null); } finally { sendAndStateLock.unlock(); } } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((sessionData == null) ? 0 : sessionData.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } S6aSession other = (S6aSession) obj; if (sessionData == null) { if (other.sessionData != null) { return false; } } else if (!sessionData.equals(other.sessionData)) { return false; } return true; } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import java.io.Serializable; import org.jdiameter.api.Request; import org.jdiameter.common.api.app.AppSessionDataLocalImpl; import org.jdiameter.common.api.app.s6a.IS6aSessionData; import org.jdiameter.common.api.app.s6a.S6aSessionState; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class S6aLocalSessionDataImpl extends AppSessionDataLocalImpl implements IS6aSessionData { protected S6aSessionState state = S6aSessionState.IDLE; protected Request buffer; protected Serializable tsTimerId; public void setS6aSessionState(S6aSessionState state) { this.state = state; } public S6aSessionState getS6aSessionState() { return this.state; } public Serializable getTsTimerId() { return this.tsTimerId; } public void setTsTimerId(Serializable tid) { this.tsTimerId = tid; } public void setBuffer(Request buffer) { this.buffer = buffer; } public Request getBuffer() { return this.buffer; } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JAuthenticationInformationAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JAuthenticationInformationAnswerImpl extends AppAnswerEventImpl implements JAuthenticationInformationAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JAuthenticationInformationAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JAuthenticationInformationAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JCancelLocationRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JCancelLocationRequestImpl extends AppRequestEventImpl implements JCancelLocationRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JCancelLocationRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JInsertSubscriberDataAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JInsertSubscriberDataAnswerImpl extends AppAnswerEventImpl implements JInsertSubscriberDataAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JInsertSubscriberDataAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JInsertSubscriberDataAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JDeleteSubscriberDataRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JDeleteSubscriberDataRequestImpl extends AppRequestEventImpl implements JDeleteSubscriberDataRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JDeleteSubscriberDataRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JAuthenticationInformationRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JAuthenticationInformationRequestImpl extends AppRequestEventImpl implements JAuthenticationInformationRequest{ private static final long serialVersionUID = 1L; /** * * @param message */ public JAuthenticationInformationRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JInsertSubscriberDataRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JInsertSubscriberDataRequestImpl extends AppRequestEventImpl implements JInsertSubscriberDataRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JInsertSubscriberDataRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JUpdateLocationRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JUpdateLocationRequestImpl extends AppRequestEventImpl implements JUpdateLocationRequest{ private static final long serialVersionUID = 1L; /** * * @param message */ public JUpdateLocationRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.IllegalDiameterStateException; import org.jdiameter.api.InternalException; import org.jdiameter.api.OverloadException; import org.jdiameter.api.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.s6a.ClientS6aSession; import org.jdiameter.api.s6a.ClientS6aSessionListener; import org.jdiameter.api.s6a.ServerS6aSession; import org.jdiameter.api.s6a.ServerS6aSessionListener; import org.jdiameter.api.s6a.events.JAuthenticationInformationAnswer; import org.jdiameter.api.s6a.events.JAuthenticationInformationRequest; import org.jdiameter.api.s6a.events.JCancelLocationAnswer; import org.jdiameter.api.s6a.events.JCancelLocationRequest; import org.jdiameter.api.s6a.events.JDeleteSubscriberDataAnswer; import org.jdiameter.api.s6a.events.JDeleteSubscriberDataRequest; import org.jdiameter.api.s6a.events.JInsertSubscriberDataAnswer; import org.jdiameter.api.s6a.events.JInsertSubscriberDataRequest; import org.jdiameter.api.s6a.events.JNotifyAnswer; import org.jdiameter.api.s6a.events.JNotifyRequest; import org.jdiameter.api.s6a.events.JPurgeUEAnswer; import org.jdiameter.api.s6a.events.JPurgeUERequest; import org.jdiameter.api.s6a.events.JResetAnswer; import org.jdiameter.api.s6a.events.JResetRequest; import org.jdiameter.api.s6a.events.JUpdateLocationAnswer; import org.jdiameter.api.s6a.events.JUpdateLocationRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.s6a.IClientS6aSessionData; import org.jdiameter.client.impl.app.s6a.S6aClientSessionImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.s6a.IS6aMessageFactory; import org.jdiameter.common.api.app.s6a.IS6aSessionData; import org.jdiameter.common.api.app.s6a.IS6aSessionFactory; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.server.impl.app.s6a.IServerS6aSessionData; import org.jdiameter.server.impl.app.s6a.S6aServerSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class S6aSessionFactoryImpl implements IS6aSessionFactory, ServerS6aSessionListener, ClientS6aSessionListener, IS6aMessageFactory, StateChangeListener<AppSession> { private static final Logger logger = LoggerFactory.getLogger(S6aSessionFactoryImpl.class); protected ISessionFactory sessionFactory; protected ServerS6aSessionListener serverSessionListener; protected ClientS6aSessionListener clientSessionListener; protected IS6aMessageFactory messageFactory; protected StateChangeListener<AppSession> stateListener; protected ISessionDatasource iss; protected IAppSessionDataFactory<IS6aSessionData> sessionDataFactory; public S6aSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IS6aSessionData>) this.iss.getDataFactory(IS6aSessionData.class); } /** * @return the serverSessionListener */ public ServerS6aSessionListener getServerSessionListener() { return serverSessionListener != null ? serverSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerS6aSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the serverSessionListener */ public ClientS6aSessionListener getClientSessionListener() { return clientSessionListener != null ? clientSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setClientSessionListener(ClientS6aSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the messageFactory */ public IS6aMessageFactory getMessageFactory() { return messageFactory != null ? messageFactory: this; } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(IS6aMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { return stateListener != null ? stateListener : this; } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if (!this.iss.exists(sessionId)) { return null; } AppSession appSession = null; try { if (aClass == ServerS6aSession.class) { IServerS6aSessionData sessionData = (IServerS6aSessionData) this.sessionDataFactory.getAppSessionData(ServerS6aSession.class, sessionId); S6aServerSessionImpl serverSession = new S6aServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getServerSessionListener()); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else if (aClass == ClientS6aSession.class) { IClientS6aSessionData sessionData = (IClientS6aSessionData) this.sessionDataFactory.getAppSessionData(ClientS6aSession.class, sessionId); S6aClientSessionImpl clientSession = new S6aClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getClientSessionListener()); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ServerS6aSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new S6a Session.", e); } return appSession; } /* * (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionFactory#getNewSession(java.lang.String, java.lang.Class, org.jdiameter.api.ApplicationId, java.lang.Object[]) */ public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { AppSession appSession = null; if (aClass == ServerS6aSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerS6aSessionData sessionData = (IServerS6aSessionData) this.sessionDataFactory.getAppSessionData(ServerS6aSession.class, sessionId); S6aServerSessionImpl serverSession = new S6aServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getServerSessionListener()); iss.addSession(serverSession); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else if (aClass == ClientS6aSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientS6aSessionData sessionData = (IClientS6aSessionData) this.sessionDataFactory.getAppSessionData(ClientS6aSession.class, sessionId); S6aClientSessionImpl clientSession = new S6aClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getClientSessionListener()); iss.addSession(clientSession); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ServerS6aSession.class + "]"); } return appSession; } /* * (non-Javadoc) * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Enum, java.lang.Enum) */ public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter S6a Session Factory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } public long getApplicationId() { return 16777251; } /* * (non-Javadoc) * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter S6a Session Factory :: stateChanged :: Session, [{}], oldState[{}], newState[{}]", new Object[]{source, oldState, newState}); } public JAuthenticationInformationAnswer createAuthenticationInformationAnswer(Answer answer) { return new JAuthenticationInformationAnswerImpl(answer); } public JAuthenticationInformationRequest createAuthenticationInformationRequest(Request request) { return new JAuthenticationInformationRequestImpl(request); } public JUpdateLocationRequest createUpdateLocationRequest(Request request) { return new JUpdateLocationRequestImpl(request); } public JUpdateLocationAnswer createUpdateLocationAnswer(Answer answer) { return new JUpdateLocationAnswerImpl(answer); } public JPurgeUERequest createPurgeUERequest(Request request) { return new JPurgeUERequestImpl(request); } public JPurgeUEAnswer createPurgeUEAnswer(Answer answer) { return new JPurgeUEAnswerImpl(answer); } public JCancelLocationRequest createCancelLocationRequest(Request request) { return new JCancelLocationRequestImpl(request); } public JCancelLocationAnswer createCancelLocationAnswer(Answer answer) { return new JCancelLocationAnswerImpl(answer); } public JInsertSubscriberDataRequest createInsertSubscriberDataRequest(Request request) { return new JInsertSubscriberDataRequestImpl(request); } public JInsertSubscriberDataAnswer createInsertSubscriberDataAnswer(Answer answer) { return new JInsertSubscriberDataAnswerImpl(answer); } public JDeleteSubscriberDataRequest createDeleteSubscriberDataRequest(Request request) { return new JDeleteSubscriberDataRequestImpl(request); } public JDeleteSubscriberDataAnswer createDeleteSubscriberDataAnswer(Answer answer) { return new JDeleteSubscriberDataAnswerImpl(answer); } public JResetRequest createResetRequest(Request request) { return new JResetRequestImpl(request); } public JResetAnswer createResetAnswer(Answer answer) { return new JResetAnswerImpl(answer); } public JNotifyRequest createNotifyRequest(Request request) { return new JNotifyRequestImpl(request); } public JNotifyAnswer createNotifyAnswer(Answer answer) { return new JNotifyAnswerImpl(answer); } public void doAuthenticationInformationRequestEvent(ServerS6aSession appSession, JAuthenticationInformationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doAuthenticationInformationRequest :: appSession[{}], Request[{}]", appSession, request); } public void doPurgeUERequestEvent(ServerS6aSession appSession, JPurgeUERequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doPurgeUERequest :: appSession[{}], Request[{}]", appSession, request); } public void doUpdateLocationRequestEvent(ServerS6aSession appSession, JUpdateLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doUpdateLocationRequest :: appSession[{}], Request[{}]", appSession, request); } public void doNotifyRequestEvent(ServerS6aSession appSession, JNotifyRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doNotifyRequest :: appSession[{}], Request[{}]", appSession, request); } public void doCancelLocationAnswerEvent(ServerS6aSession appSession, JCancelLocationRequest request, JCancelLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doCancelLocationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doInsertSubscriberDataAnswerEvent(ServerS6aSession appSession, JInsertSubscriberDataRequest request, JInsertSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doDeleteSubscriberDataAnswerEvent(ServerS6aSession appSession, JDeleteSubscriberDataRequest request, JDeleteSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doResetAnswerEvent(ServerS6aSession appSession, JResetRequest request, JResetAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doResetAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doCancelLocationRequestEvent(ClientS6aSession appSession, JCancelLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doCancelLocationRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request}); } public void doInsertSubscriberDataRequestEvent(ClientS6aSession appSession, JInsertSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request}); } public void doDeleteSubscriberDataRequestEvent(ClientS6aSession appSession, JDeleteSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request}); } public void doResetRequestEvent(ClientS6aSession appSession, JResetRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doResetRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request}); } public void doAuthenticationInformationAnswerEvent(ClientS6aSession appSession, JAuthenticationInformationRequest request, JAuthenticationInformationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doAuthenticationInformationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doPurgeUEAnswerEvent(ClientS6aSession appSession, JPurgeUERequest request, JPurgeUEAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doPurgeUEAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doUpdateLocationAnswerEvent(ClientS6aSession appSession, JUpdateLocationRequest request, JUpdateLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doUpdateLocationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doNotifyAnswerEvent(ClientS6aSession appSession, JNotifyRequest request, JNotifyAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter S6a Session Factory :: doNotifyAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JResetAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JResetAnswerImpl extends AppAnswerEventImpl implements JResetAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JResetAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JResetAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JCancelLocationAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JCancelLocationAnswerImpl extends AppAnswerEventImpl implements JCancelLocationAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JCancelLocationAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JCancelLocationAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.s6a.events.JUpdateLocationAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a> */ public class JUpdateLocationAnswerImpl extends AppAnswerEventImpl implements JUpdateLocationAnswer { private static final long serialVersionUID = 1L; /** * * @param answer */ public JUpdateLocationAnswerImpl(Answer answer) { super(answer); } /** * * @param request * @param resultCode */ public JUpdateLocationAnswerImpl(Request request, long resultCode) { super(request.createAnswer(resultCode)); } }
Java
/* * 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.jdiameter.common.impl.app.s6a; import org.jdiameter.api.Message; import org.jdiameter.api.s6a.events.JNotifyRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class JNotifyRequestImpl extends AppRequestEventImpl implements JNotifyRequest { private static final long serialVersionUID = 1L; /** * * @param message */ public JNotifyRequestImpl(Message message) { super(message); message.setRequest(true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppAnswerEvent; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AppAnswerEventImpl extends AppEventImpl implements AppAnswerEvent { private static final long serialVersionUID = 1L; public AppAnswerEventImpl(Request request, long resultCode) { this(request.createAnswer(resultCode)); } public AppAnswerEventImpl(Request request, long vendorId, long resultCode) { this(request.createAnswer(vendorId, resultCode)); } public AppAnswerEventImpl(Request request) { this(request.createAnswer()); } public AppAnswerEventImpl(Answer answer) { super(answer); } public Avp getResultCodeAvp() throws AvpDataException { Avp resultCodeAvp = message.getAvps().getAvp(Avp.RESULT_CODE); return resultCodeAvp != null ? resultCodeAvp : message.getAvps().getAvp(Avp.EXPERIMENTAL_RESULT_CODE); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.gx.ClientGxSession; import org.jdiameter.api.gx.ServerGxSession; import org.jdiameter.client.impl.app.gx.ClientGxSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.gx.IGxSessionData; import org.jdiameter.server.impl.app.gx.ServerGxSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class GxLocalSessionDataFactory implements IAppSessionDataFactory<IGxSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IGxSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientGxSession.class)) { ClientGxSessionDataLocalImpl data = new ClientGxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerGxSession.class)) { ServerGxSessionDataLocalImpl data = new ServerGxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.app.StateMachine; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.gx.IGxSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> */ public abstract class AppGxSessionImpl extends AppSessionImpl implements NetworkReqListener, StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); //FIXME: those must be recreated from local resources! //FIXME: change this to single ref! protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); public AppGxSessionImpl(ISessionFactory sf, IGxSessionData sessionData) { super(sf, sessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public void release() { //stateListeners.clear(); super.release(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.gx.events.GxCreditControlRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> */ public class GxCreditControlRequestImpl extends AppRequestEventImpl implements GxCreditControlRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(GxCreditControlRequestImpl.class); private static final int REQUESTED_ACTION_AVP_CODE = 436; private static final int CC_REQUEST_TYPE_AVP_CODE = 416; public GxCreditControlRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public GxCreditControlRequestImpl(Request request) { super(request); } public boolean isRequestedActionAVPPresent() { return super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE) != null; } public int getRequestedActionAVPValue() { Avp requestedActionAvp = super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE); if (requestedActionAvp != null) { try { return requestedActionAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Requested-Action AVP value", e); } } return -1; } public boolean isRequestTypeAVPPresent() { return super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE) != null; } public int getRequestTypeAVPValue() { Avp requestTypeAvp = super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE); if (requestTypeAvp != null) { try { return requestTypeAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain CC-Request-Type AVP value", e); } } return -1; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import java.util.concurrent.ScheduledFuture; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.InternalException; import org.jdiameter.api.Message; import org.jdiameter.api.Request; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.gx.events.GxReAuthAnswer; import org.jdiameter.api.gx.events.GxReAuthRequest; import org.jdiameter.api.gx.ClientGxSession; import org.jdiameter.api.gx.ClientGxSessionListener; import org.jdiameter.api.gx.ServerGxSession; import org.jdiameter.api.gx.ServerGxSessionListener; import org.jdiameter.api.gx.events.GxCreditControlAnswer; import org.jdiameter.api.gx.events.GxCreditControlRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.gx.ClientGxSessionImpl; import org.jdiameter.client.impl.app.gx.IClientGxSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.gx.IClientGxSessionContext; import org.jdiameter.common.api.app.gx.IGxMessageFactory; import org.jdiameter.common.api.app.gx.IGxSessionData; import org.jdiameter.common.api.app.gx.IGxSessionFactory; import org.jdiameter.common.api.app.gx.IServerGxSessionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.app.gx.GxReAuthAnswerImpl; import org.jdiameter.common.impl.app.gx.GxReAuthRequestImpl; import org.jdiameter.server.impl.app.gx.IServerGxSessionData; import org.jdiameter.server.impl.app.gx.ServerGxSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Gx Session Factory implementation. * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> */ public class GxSessionFactoryImpl implements IGxSessionFactory, ClientGxSessionListener, ServerGxSessionListener, StateChangeListener<AppSession>, IGxMessageFactory, IServerGxSessionContext, IClientGxSessionContext { // Message timeout value (in milliseconds) protected int defaultDirectDebitingFailureHandling = 0; protected int defaultCreditControlFailureHandling = 0; // its seconds protected long defaultValidityTime = 60; protected long defaultTxTimerValue = 30; // local not replicated listeners: protected ClientGxSessionListener clientSessionListener; protected ServerGxSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected IServerGxSessionContext serverContextListener; protected IClientGxSessionContext clientContextListener; protected IGxMessageFactory messageFactory; protected Logger logger = LoggerFactory.getLogger(GxSessionFactoryImpl.class); protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected IAppSessionDataFactory<IGxSessionData> sessionDataFactory; public GxSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IGxSessionData>) this.iss.getDataFactory(IGxSessionData.class); } public GxSessionFactoryImpl(SessionFactory sessionFactory, int defaultDirectDebitingFailureHandling, int defaultCreditControlFailureHandling, long defaultValidityTime, long defaultTxTimerValue) { this(sessionFactory); this.defaultDirectDebitingFailureHandling = defaultDirectDebitingFailureHandling; this.defaultCreditControlFailureHandling = defaultCreditControlFailureHandling; this.defaultValidityTime = defaultValidityTime; this.defaultTxTimerValue = defaultTxTimerValue; } /** * @return the clientSessionListener */ public ClientGxSessionListener getClientSessionListener() { return clientSessionListener != null ? clientSessionListener : this; } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(final ClientGxSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the serverSessionListener */ public ServerGxSessionListener getServerSessionListener() { return serverSessionListener != null ? serverSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerGxSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the serverContextListener */ public IServerGxSessionContext getServerContextListener() { return serverContextListener != null ? serverContextListener : this; } /** * @param serverContextListener * the serverContextListener to set */ public void setServerContextListener(IServerGxSessionContext serverContextListener) { this.serverContextListener = serverContextListener; } /** * @return the clientContextListener */ public IClientGxSessionContext getClientContextListener() { return clientContextListener != null ? clientContextListener : this; } /** * @return the messageFactory */ public IGxMessageFactory getMessageFactory() { return messageFactory != null ? messageFactory : this; } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(final IGxMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @param clientContextListener * the clientContextListener to set */ public void setClientContextListener(IClientGxSessionContext clientContextListener) { this.clientContextListener = clientContextListener; } /** * @return the sessionFactory */ public SessionFactory getSessionFactory() { return sessionFactory; } /** * @param sessionFactory * the sessionFactory to set */ public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = (ISessionFactory) sessionFactory; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { return stateListener != null ? stateListener : this; } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if(!this.iss.exists(sessionId)) { return null; } AppSession appSession = null; try { if (aClass == ClientGxSession.class) { IClientGxSessionData sessionData = (IClientGxSessionData) this.sessionDataFactory.getAppSessionData(ClientGxSession.class, sessionId); ClientGxSessionImpl clientSession = new ClientGxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerGxSession.class) { IServerGxSessionData sessionData = (IServerGxSessionData) this.sessionDataFactory.getAppSessionData(ServerGxSession.class, sessionId); ServerGxSessionImpl serverSession = new ServerGxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientGxSession.class + "," + ServerGxSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Gx Session.", e); } return appSession; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { AppSession appSession = null; try { // FIXME: if (aClass == ClientGxSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientGxSessionData sessionData = (IClientGxSessionData) this.sessionDataFactory.getAppSessionData(ClientGxSession.class, sessionId); sessionData.setApplicationId(applicationId); ClientGxSessionImpl clientSession = new ClientGxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); // this goes first! iss.addSession(clientSession); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerGxSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerGxSessionData sessionData = (IServerGxSessionData) this.sessionDataFactory.getAppSessionData(ServerGxSession.class, sessionId); sessionData.setApplicationId(applicationId); ServerGxSessionImpl serverSession = new ServerGxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); iss.addSession(serverSession); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientGxSession.class + "," + ServerGxSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Gx Session.", e); } return appSession; } // Default implementation of methods so there are no exception! // Message Handlers -------------------------------------------------------- public void doCreditControlRequest(ServerGxSession session, GxCreditControlRequest request) throws InternalException { } public void doCreditControlAnswer(ClientGxSession session, GxCreditControlRequest request, GxCreditControlAnswer answer) throws InternalException { } public void doGxReAuthRequest(ClientGxSession session, GxReAuthRequest request) throws InternalException { } public void doGxReAuthAnswer(ServerGxSession session, GxReAuthRequest request, GxReAuthAnswer answer) throws InternalException { } public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException { } // Message Factory Methods ------------------------------------------------- public GxCreditControlAnswer createCreditControlAnswer(Answer answer) { return new GxCreditControlAnswerImpl(answer); } public GxCreditControlRequest createCreditControlRequest(Request req) { return new GxCreditControlRequestImpl(req); } public GxReAuthAnswer createGxReAuthAnswer(Answer answer) { return new GxReAuthAnswerImpl(answer); } public GxReAuthRequest createGxReAuthRequest(Request req) { return new GxReAuthRequestImpl(req); } // Context Methods --------------------------------------------------------- @SuppressWarnings("unchecked") public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter Gx SessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ @SuppressWarnings("unchecked") public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Gx SessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[]{source, oldState, newState}); } // FIXME: add ctx methods proxy calls! public void sessionSupervisionTimerExpired(ServerGxSession session) { // this.resourceAdaptor.sessionDestroyed(session.getSessions().get(0).getSessionId(), session); session.release(); } @SuppressWarnings("unchecked") public void sessionSupervisionTimerReStarted(ServerGxSession session, ScheduledFuture future) { // TODO Complete this method. } @SuppressWarnings("unchecked") public void sessionSupervisionTimerStarted(ServerGxSession session, ScheduledFuture future) { // TODO Complete this method. } @SuppressWarnings("unchecked") public void sessionSupervisionTimerStopped(ServerGxSession session, ScheduledFuture future) { // TODO Complete this method. } public void timeoutExpired(Request request) { // FIXME What should we do when there's a timeout? } public void denyAccessOnDeliverFailure(ClientGxSession clientGxSessionImpl, Message request) { // TODO Complete this method. } public void denyAccessOnFailureMessage(ClientGxSession clientGxSessionImpl) { // TODO Complete this method. } public void denyAccessOnTxExpire(ClientGxSession clientGxSessionImpl) { // this.resourceAdaptor.sessionDestroyed(clientGxSessionImpl.getSessions().get(0).getSessionId(), // clientGxSessionImpl); clientGxSessionImpl.release(); } public int getDefaultCCFHValue() { return defaultCreditControlFailureHandling; } public int getDefaultDDFHValue() { return defaultDirectDebitingFailureHandling; } public long getDefaultTxTimerValue() { return defaultTxTimerValue; } public void grantAccessOnDeliverFailure(ClientGxSession clientGxSessionImpl, Message request) { // TODO Auto-generated method stub } public void grantAccessOnFailureMessage(ClientGxSession clientGxSessionImpl) { // TODO Auto-generated method stub } public void grantAccessOnTxExpire(ClientGxSession clientGxSessionImpl) { // TODO Auto-generated method stub } public void indicateServiceError(ClientGxSession clientGxSessionImpl) { // TODO Auto-generated method stub } public void txTimerExpired(ClientGxSession session) { // this.resourceAdaptor.sessionDestroyed(session.getSessions().get(0).getSessionId(), session); session.release(); } public long[] getApplicationIds() { // FIXME: What should we do here? return new long[] {16777238, 16777238}; } public long getDefaultValidityTime() { return this.defaultValidityTime; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.gx.events.GxReAuthRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> */ public class GxReAuthRequestImpl extends AppRequestEventImpl implements GxReAuthRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(GxReAuthRequestImpl.class); public GxReAuthRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public GxReAuthRequestImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.gx.events.GxCreditControlAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class GxCreditControlAnswerImpl extends AppAnswerEventImpl implements GxCreditControlAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(GxCreditControlAnswerImpl.class); private static final int CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE = 427; private static final int DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE = 428; private static final int REQUESTED_ACTION_AVP_CODE = 436; private static final int CC_REQUEST_TYPE_AVP_CODE = 416; private static final int VALIDITY_TIME_AVP_CODE = 448; /** * @param answer */ public GxCreditControlAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public GxCreditControlAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public GxCreditControlAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public GxCreditControlAnswerImpl(Request request) { super(request); } public boolean isCreditControlFailureHandlingAVPPresent() { return super.message.getAvps().getAvp(CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE) != null; } public int getCredidControlFailureHandlingAVPValue() { Avp credidControlFailureHandlingAvp = super.message.getAvps().getAvp(CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE); if (credidControlFailureHandlingAvp != null) { try { return credidControlFailureHandlingAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Credit-Control-Failure-Handling AVP value", e); } } return -1; } public boolean isDirectDebitingFailureHandlingAVPPresent() { return super.message.getAvps().getAvp(DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE) != null; } public int getDirectDebitingFailureHandlingAVPValue() { Avp directDebitingFailureHandlingAvp = super.message.getAvps().getAvp(DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE); if (directDebitingFailureHandlingAvp != null) { try { return directDebitingFailureHandlingAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Direct-Debiting-Failure-Handling AVP value", e); } } return -1; } public Avp getValidityTimeAvp() { return super.message.getAvps().getAvp(VALIDITY_TIME_AVP_CODE); } public boolean isRequestTypeAVPPresent() { return super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE) != null; } public int getRequestTypeAVPValue() { Avp requestTypeAvp = super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE); if (requestTypeAvp != null) { try { return requestTypeAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain CC-Request-Type AVP value", e); } } return -1; } public boolean isRequestedActionAVPPresent() { return super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE) != null; } public int getRequestedActionAVPValue() { Avp requestedActionAvp = super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE); if (requestedActionAvp != null) { try { return requestedActionAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Requested-Action AVP value", e); } } return -1; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.gx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.gx.events.GxReAuthAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author <a href="mailto:carl-magnus.bjorkell@emblacom.com"> Carl-Magnus Björkell </a> */ public class GxReAuthAnswerImpl extends AppAnswerEventImpl implements GxReAuthAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(GxReAuthAnswerImpl.class); public GxReAuthAnswerImpl(Request message, long resultCode) { super(message.createAnswer(resultCode)); } public GxReAuthAnswerImpl(Answer message) { super(message); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app; import static org.jdiameter.api.Avp.ORIGIN_HOST; import static org.jdiameter.api.Avp.ORIGIN_REALM; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.InternalException; import org.jdiameter.api.Message; import org.jdiameter.api.app.AppEvent; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AppEventImpl implements AppEvent { private static final long serialVersionUID = 1L; protected Message message; public AppEventImpl(Message message) { this.message = message; } public int getCommandCode() { return message.getCommandCode(); } public Message getMessage() throws InternalException { return message; } public String getOriginHost() throws AvpDataException { Avp originHostAvp = message.getAvps().getAvp(ORIGIN_HOST); if (originHostAvp != null) { return originHostAvp.getDiameterIdentity(); } else { throw new AvpDataException("Avp ORIGIN_HOST not found"); } } public String getOriginRealm() throws AvpDataException { Avp originRealmAvp = message.getAvps().getAvp(ORIGIN_REALM); if (originRealmAvp != null) { return originRealmAvp.getDiameterIdentity(); } else { throw new AvpDataException("Avp ORIGIN_REALM not found"); } } public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AppEventImpl that = (AppEventImpl) o; return message.equals(that.message); } public int hashCode() { return message.hashCode(); } public String toString() { return message != null ? message.toString() : "empty"; } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.rx.events.RxAAAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxAAAnswerImpl extends AppAnswerEventImpl implements RxAAAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxAAAnswerImpl.class); public RxAAAnswerImpl(Request message, long resultCode) { super(message.createAnswer(resultCode)); } public RxAAAnswerImpl(Answer message) { super(message); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rx.events.RxReAuthRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxReAuthRequestImpl extends AppRequestEventImpl implements RxReAuthRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxReAuthRequestImpl.class); public RxReAuthRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public RxReAuthRequestImpl(Request request) { super(request); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.rx.events.RxSessionTermAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxSessionTermAnswerImpl extends AppAnswerEventImpl implements RxSessionTermAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxSessionTermAnswerImpl.class); public RxSessionTermAnswerImpl(Request message, long resultCode) { super(message.createAnswer(resultCode)); } public RxSessionTermAnswerImpl(Answer message) { super(message); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.rx.events.RxAbortSessionAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxAbortSessionAnswerImpl extends AppAnswerEventImpl implements RxAbortSessionAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxAbortSessionAnswerImpl.class); public RxAbortSessionAnswerImpl(Request message, long resultCode) { super(message.createAnswer(resultCode)); } public RxAbortSessionAnswerImpl(Answer message) { super(message); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import java.util.concurrent.ScheduledFuture; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.InternalException; import org.jdiameter.api.Message; import org.jdiameter.api.Request; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; //import org.jdiameter.api.auth.events.ReAuthAnswer; //import org.jdiameter.api.auth.events.ReAuthRequest; import org.jdiameter.api.rx.events.RxReAuthAnswer; import org.jdiameter.api.rx.events.RxReAuthRequest; //import org.jdiameter.api.auth.events.AbortSessionAnswer; //import org.jdiameter.api.auth.events.AbortSessionRequest; import org.jdiameter.api.rx.events.RxAbortSessionAnswer; import org.jdiameter.api.rx.events.RxAbortSessionRequest; //import org.jdiameter.api.auth.events.SessionTermAnswer; //import org.jdiameter.api.auth.events.SessionTermRequest; import org.jdiameter.api.rx.events.RxSessionTermAnswer; import org.jdiameter.api.rx.events.RxSessionTermRequest; import org.jdiameter.api.rx.ClientRxSession; import org.jdiameter.api.rx.ClientRxSessionListener; import org.jdiameter.api.rx.ServerRxSession; import org.jdiameter.api.rx.ServerRxSessionListener; import org.jdiameter.api.rx.events.RxAAAnswer; import org.jdiameter.api.rx.events.RxAARequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.rx.ClientRxSessionImpl; import org.jdiameter.client.impl.app.rx.IClientRxSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.rx.IRxSessionData; import org.jdiameter.common.api.app.rx.IClientRxSessionContext; import org.jdiameter.common.api.app.rx.IRxMessageFactory; import org.jdiameter.common.api.app.rx.IRxSessionFactory; import org.jdiameter.common.api.app.rx.IServerRxSessionContext; import org.jdiameter.common.api.data.ISessionDatasource; //import org.jdiameter.common.impl.app.auth.ReAuthAnswerImpl; //import org.jdiameter.common.impl.app.auth.ReAuthRequestImpl; //import org.jdiameter.common.impl.app.auth.AbortSessionAnswerImpl; //import org.jdiameter.common.impl.app.auth.AbortSessionRequestImpl; //import org.jdiameter.common.impl.app.auth.SessionTermAnswerImpl; //import org.jdiameter.common.impl.app.auth.SessionTermRequestImpl; import org.jdiameter.server.impl.app.rx.IServerRxSessionData; import org.jdiameter.server.impl.app.rx.ServerRxSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Rx Session Factory implementation. * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxSessionFactoryImpl implements IRxSessionFactory, ClientRxSessionListener, ServerRxSessionListener, StateChangeListener<AppSession>, IRxMessageFactory, IServerRxSessionContext, IClientRxSessionContext { // Message timeout value (in milliseconds) protected int defaultDirectDebitingFailureHandling = 0; protected int defaultAAFailureHandling = 0; // its seconds protected long defaultValidityTime = 60; protected long defaultTxTimerValue = 30; // local not replicated listeners: protected ClientRxSessionListener clientSessionListener; protected ServerRxSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected IServerRxSessionContext serverContextListener; protected IClientRxSessionContext clientContextListener; protected IRxMessageFactory messageFactory; protected Logger logger = LoggerFactory.getLogger(RxSessionFactoryImpl.class); protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected IAppSessionDataFactory<IRxSessionData> sessionDataFactory; public RxSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IRxSessionData>) this.iss.getDataFactory(IRxSessionData.class); if(this.sessionDataFactory == null) { logger.debug("Initialized Rx SessionDataFactory is null"); } } public RxSessionFactoryImpl(SessionFactory sessionFactory, int defaultDirectDebitingFailureHandling, int defaultAAFailureHandling, long defaultValidityTime, long defaultTxTimerValue) { this(sessionFactory); this.defaultDirectDebitingFailureHandling = defaultDirectDebitingFailureHandling; this.defaultAAFailureHandling = defaultAAFailureHandling; this.defaultValidityTime = defaultValidityTime; this.defaultTxTimerValue = defaultTxTimerValue; } /** * @return the clientSessionListener */ public ClientRxSessionListener getClientSessionListener() { return clientSessionListener != null ? clientSessionListener : this; } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(final ClientRxSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the serverSessionListener */ public ServerRxSessionListener getServerSessionListener() { return serverSessionListener != null ? serverSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerRxSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the serverContextListener */ public IServerRxSessionContext getServerContextListener() { return serverContextListener != null ? serverContextListener : this; } /** * @param serverContextListener * the serverContextListener to set */ public void setServerContextListener(IServerRxSessionContext serverContextListener) { this.serverContextListener = serverContextListener; } /** * @return the clientContextListener */ public IClientRxSessionContext getClientContextListener() { return clientContextListener != null ? clientContextListener : this; } /** * @return the messageFactory */ public IRxMessageFactory getMessageFactory() { return messageFactory != null ? messageFactory : this; } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(final IRxMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @param clientContextListener * the clientContextListener to set */ public void setClientContextListener(IClientRxSessionContext clientContextListener) { this.clientContextListener = clientContextListener; } /** * @return the sessionFactory */ public SessionFactory getSessionFactory() { return sessionFactory; } /** * @param sessionFactory * the sessionFactory to set */ public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = (ISessionFactory) sessionFactory; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { return stateListener != null ? stateListener : this; } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if(!this.iss.exists(sessionId)) { return null; } AppSession appSession = null; try { if (aClass == ClientRxSession.class) { IClientRxSessionData sessionData = (IClientRxSessionData) this.sessionDataFactory.getAppSessionData(ClientRxSession.class, sessionId); ClientRxSessionImpl clientSession = new ClientRxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerRxSession.class) { IServerRxSessionData sessionData = (IServerRxSessionData) this.sessionDataFactory.getAppSessionData(ServerRxSession.class, sessionId); ServerRxSessionImpl serverSession = new ServerRxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRxSession.class + "," + ServerRxSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Rx Session.", e); } return appSession; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { AppSession appSession = null; try { // FIXME: if (aClass == ClientRxSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientRxSessionData sessionData = (IClientRxSessionData) this.sessionDataFactory.getAppSessionData(ClientRxSession.class, sessionId); ClientRxSessionImpl clientSession = new ClientRxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); // this goes first! iss.addSession(clientSession); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerRxSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerRxSessionData sessionData = (IServerRxSessionData) this.sessionDataFactory.getAppSessionData(ServerRxSession.class, sessionId); ServerRxSessionImpl serverSession = new ServerRxSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); iss.addSession(serverSession); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRxSession.class + "," + ServerRxSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Rx Session.", e); } return appSession; } // Default implementation of methods so there are no exception! // Message Handlers -------------------------------------------------------- public void doAARequest(ServerRxSession session, RxAARequest request) throws InternalException { } public void doAAAnswer(ClientRxSession session, RxAARequest request, RxAAAnswer answer) throws InternalException { } public void doReAuthRequest(ClientRxSession session, RxReAuthRequest request) throws InternalException { } public void doReAuthAnswer(ServerRxSession session, RxReAuthRequest request, RxReAuthAnswer answer) throws InternalException { } public void doAbortSessionRequest(ClientRxSession session, RxAbortSessionRequest request) throws InternalException { } public void doAbortSessionAnswer(ServerRxSession session, RxAbortSessionRequest request, RxAbortSessionAnswer answer) throws InternalException { } public void doSessionTermRequest(ServerRxSession session, RxSessionTermRequest request) throws InternalException { } public void doSessionTermAnswer(ClientRxSession session, RxSessionTermRequest request, RxSessionTermAnswer answer) throws InternalException { } public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException { } // Message Factory Methods ------------------------------------------------- public RxAAAnswer createAAAnswer(Answer answer) { return new RxAAAnswerImpl(answer); } public RxAARequest createAARequest(Request req) { return new RxAARequestImpl(req); } public RxReAuthAnswer createReAuthAnswer(Answer answer) { return new RxReAuthAnswerImpl(answer); } public RxReAuthRequest createReAuthRequest(Request req) { return new RxReAuthRequestImpl(req); } public RxSessionTermAnswer createSessionTermAnswer(Answer answer) { return new RxSessionTermAnswerImpl(answer); } public RxSessionTermRequest createSessionTermRequest(Request req) { return new RxSessionTermRequestImpl(req); } public RxAbortSessionAnswer createAbortSessionAnswer(Answer answer) { return new RxAbortSessionAnswerImpl(answer); } public RxAbortSessionRequest createAbortSessionRequest(Request req) { return new RxAbortSessionRequestImpl(req); } // Context Methods ---------------------------------------------------------- public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter Rx SessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Rx SessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[]{source, oldState, newState}); } // FIXME: add ctx methods proxy calls! public void sessionSupervisionTimerExpired(ServerRxSession session) { // this.resourceAdaptor.sessionDestroyed(session.getSessions().get(0).getSessionId(), session); session.release(); } public void sessionSupervisionTimerReStarted(ServerRxSession session, ScheduledFuture future) { // TODO Complete this method. } public void sessionSupervisionTimerStarted(ServerRxSession session, ScheduledFuture future) { // TODO Complete this method. } public void sessionSupervisionTimerStopped(ServerRxSession session, ScheduledFuture future) { // TODO Complete this method. } public void timeoutExpired(Request request) { // FIXME What should we do when there's a timeout? } public void denyAccessOnDeliverFailure(ClientRxSession clientRxSessionImpl, Message request) { // TODO Complete this method. } public void denyAccessOnFailureMessage(ClientRxSession clientRxSessionImpl) { // TODO Complete this method. } public void denyAccessOnTxExpire(ClientRxSession clientRxSessionImpl) { // this.resourceAdaptor.sessionDestroyed(clientRxSessionImpl.getSessions().get(0).getSessionId(), // clientRxSessionImpl); clientRxSessionImpl.release(); } public void grantAccessOnDeliverFailure(ClientRxSession clientRxSessionImpl, Message request) { // TODO Auto-generated method stub } public void grantAccessOnFailureMessage(ClientRxSession clientRxSessionImpl) { // TODO Auto-generated method stub } public void grantAccessOnTxExpire(ClientRxSession clientRxSessionImpl) { // TODO Auto-generated method stub } public void indicateServiceError(ClientRxSession clientRxSessionImpl) { // TODO Auto-generated method stub } public long[] getApplicationIds() { // FIXME: What should we do here? return new long[]{16777236}; } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rx.events.RxAARequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxAARequestImpl extends AppRequestEventImpl implements RxAARequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxAARequestImpl.class); public RxAARequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public RxAARequestImpl(Request request) { super(request); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.rx.events.RxReAuthAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxReAuthAnswerImpl extends AppAnswerEventImpl implements RxReAuthAnswer { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxReAuthAnswerImpl.class); public RxReAuthAnswerImpl(Request message, long resultCode) { super(message.createAnswer(resultCode)); } public RxReAuthAnswerImpl(Answer message) { super(message); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rx.ClientRxSession; import org.jdiameter.api.rx.ServerRxSession; import org.jdiameter.client.impl.app.rx.ClientRxSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.rx.IRxSessionData; import org.jdiameter.server.impl.app.rx.ServerRxSessionDataLocalImpl; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxLocalSessionDataFactory implements IAppSessionDataFactory<IRxSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IRxSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientRxSession.class)) { ClientRxSessionDataLocalImpl data = new ClientRxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerRxSession.class)) { ServerRxSessionDataLocalImpl data = new ServerRxSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rx.events.RxAbortSessionRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxAbortSessionRequestImpl extends AppRequestEventImpl implements RxAbortSessionRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxAbortSessionRequestImpl.class); public RxAbortSessionRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public RxAbortSessionRequestImpl(Request request) { super(request); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rx.events.RxSessionTermRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RxSessionTermRequestImpl extends AppRequestEventImpl implements RxSessionTermRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RxSessionTermRequestImpl.class); public RxSessionTermRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public RxSessionTermRequestImpl(Request request) { super(request); } }
Java
/* * 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.jdiameter.common.impl.app.rx; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.app.StateMachine; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.rx.IRxSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public abstract class AppRxSessionImpl extends AppSessionImpl implements NetworkReqListener, StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); //FIXME: those must be recreated from local resources! //FIXME: change this to single ref! protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); public AppRxSessionImpl(ISessionFactory sf, IRxSessionData sessionData) { super(sf, sessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public void release() { super.release(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import static org.jdiameter.api.Avp.AUTH_APPLICATION_ID; import static org.jdiameter.api.Avp.RE_AUTH_REQUEST_TYPE; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Message; import org.jdiameter.api.auth.events.ReAuthRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class ReAuthRequestImpl extends AppRequestEventImpl implements ReAuthRequest { private static final long serialVersionUID = 1L; public ReAuthRequestImpl(Message message) { super(message); } public long getAuthApplicationId() throws AvpDataException { Avp authApplicationIdAvp = message.getAvps().getAvp(AUTH_APPLICATION_ID); if (authApplicationIdAvp != null) { return authApplicationIdAvp.getUnsigned32(); } else { throw new AvpDataException("Avp AUTH_APPLICATION_ID not found"); } } public int getReAuthRequestType() throws AvpDataException { Avp reAuthRequestTypeAvp = message.getAvps().getAvp(RE_AUTH_REQUEST_TYPE); if (reAuthRequestTypeAvp != null) { return reAuthRequestTypeAvp.getInteger32(); } else { throw new AvpDataException("Avp RE_AUTH_REQUEST_TYPE not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import org.jdiameter.api.Answer; 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.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.auth.ClientAuthSession; import org.jdiameter.api.auth.ClientAuthSessionListener; import org.jdiameter.api.auth.ServerAuthSession; import org.jdiameter.api.auth.ServerAuthSessionListener; import org.jdiameter.api.auth.events.AbortSessionAnswer; import org.jdiameter.api.auth.events.AbortSessionRequest; import org.jdiameter.api.auth.events.ReAuthAnswer; import org.jdiameter.api.auth.events.ReAuthRequest; import org.jdiameter.api.auth.events.SessionTermAnswer; import org.jdiameter.api.auth.events.SessionTermRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.auth.ClientAuthSessionImpl; import org.jdiameter.client.impl.app.auth.IClientAuthSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.auth.IAuthMessageFactory; import org.jdiameter.common.api.app.auth.IAuthSessionData; import org.jdiameter.common.api.app.auth.IAuthSessionFactory; import org.jdiameter.common.api.app.auth.IClientAuthActionContext; import org.jdiameter.common.api.app.auth.IServerAuthActionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.jdiameter.server.impl.app.auth.IServerAuthSessionData; import org.jdiameter.server.impl.app.auth.ServerAuthSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Authorization Session Factory implementation * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AuthSessionFactoryImpl implements IAuthSessionFactory, IAuthMessageFactory, ServerAuthSessionListener, ClientAuthSessionListener, IClientAuthActionContext, IServerAuthActionContext, StateChangeListener<AppSession> { private final static long authAppId = 19301L; protected IAuthMessageFactory messageFactory; protected ServerAuthSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected ClientAuthSessionListener clientSessionListener; protected boolean stateles; protected long messageTimeout = 5000; protected Logger logger = LoggerFactory.getLogger(AuthSessionFactoryImpl.class); protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected IServerAuthActionContext serverSessionContext; protected IClientAuthActionContext clientSessionContext; protected IAppSessionDataFactory<IAuthSessionData> sessionDataFactory; public AuthSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IAuthSessionData>) this.iss.getDataFactory(IAuthSessionData.class); } /** * @return the clientSessionContext */ public IClientAuthActionContext getClientSessionContext() { return clientSessionContext != null ? clientSessionContext : this; } /** * @param clientSessionContext * the clientSessionContext to set */ public void setClientSessionContext(IClientAuthActionContext clientSessionContext) { this.clientSessionContext = clientSessionContext; } /** * @return the serverSessionContext */ public IServerAuthActionContext getServerSessionContext() { return serverSessionContext != null ? serverSessionContext : this; } /** * @param serverSessionContext * the serverSessionContext to set */ public void setServerSessionContext(IServerAuthActionContext serverSessionContext) { this.serverSessionContext = serverSessionContext; } /** * @return the messageTimeout */ public long getMessageTimeout() { return messageTimeout; } /** * @param messageTimeout * the messageTimeout to set */ public void setMessageTimeout(long messageTimeout) { this.messageTimeout = messageTimeout; } /** * @return the messageFactory */ public IAuthMessageFactory getMessageFactory() { return messageFactory != null ? messageFactory : this; } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(IAuthMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @return the serverSessionListener */ public ServerAuthSessionListener getServerSessionListener() { return serverSessionListener != null ? serverSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerAuthSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { return stateListener != null ? stateListener : this; } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } /** * @return the clientSessionListener */ public ClientAuthSessionListener getClientSessionListener() { return clientSessionListener != null ? clientSessionListener : this; } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(ClientAuthSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } public boolean isStateles() { return stateles; } public void setStateles(boolean stateles) { this.stateles = stateles; } @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if(!this.iss.exists(sessionId)) { return null; } try { if (aClass == ServerAuthSession.class) { IServerAuthSessionData sessionData = (IServerAuthSessionData) this.sessionDataFactory.getAppSessionData(ServerAuthSession.class, sessionId); ServerAuthSessionImpl session = new ServerAuthSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getMessageFactory(), getStateListener(), getServerSessionContext(), messageTimeout, isStateles()); session.getSessions().get(0).setRequestListener(session); return session; } else { if (aClass == ClientAuthSession.class) { IClientAuthSessionData sessionData = (IClientAuthSessionData) this.sessionDataFactory.getAppSessionData(ClientAuthSession.class, sessionId); ClientAuthSessionImpl session = new ClientAuthSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getMessageFactory(), getStateListener(), getClientSessionContext(), isStateles()); session.getSessions().get(0).setRequestListener(session); return session; } } } catch (Exception e) { logger.error("Failure trying to obtain new authorization session", e); } return null; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { try { if (aClass == ServerAuthSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerAuthSessionData sessionData = (IServerAuthSessionData) this.sessionDataFactory.getAppSessionData(ServerAuthSession.class, sessionId); sessionData.setApplicationId(applicationId); ServerAuthSessionImpl session = new ServerAuthSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getMessageFactory(), getStateListener(), getServerSessionContext(), messageTimeout, isStateles()); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } else { if (aClass == ClientAuthSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientAuthSessionData sessionData = (IClientAuthSessionData) this.sessionDataFactory.getAppSessionData(ClientAuthSession.class, sessionId); sessionData.setApplicationId(applicationId); ClientAuthSessionImpl session = new ClientAuthSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getMessageFactory(), getStateListener(), getClientSessionContext(), isStateles()); iss.addSession(session); // iss.setSessionListener(clientSession.getSessionId(), (NetworkReqListener) appSession); session.getSessions().get(0).setRequestListener(session); return session; } } } catch (Exception e) { logger.error("Failure trying to obtain new authorization session", e); } return null; } // Message Factory Methods ------------------------------------------------ public AppAnswerEvent createAuthAnswer(Answer answer) { return new AppAnswerEventImpl(answer); } public AppRequestEvent createAuthRequest(Request request) { return new AppRequestEventImpl(request); } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.auth.IAuthMessageFactory#getAuthMessageCommandCode() */ public int getAuthMessageCommandCode() { return 258; } public ApplicationId getApplicationId() { return ApplicationId.createByAuthAppId(authAppId); } // Message Handlers ------------------------------------------------------- public void doAbortSessionRequestEvent(ClientAuthSession appSession, AbortSessionRequest asr) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doAbortSessionRequestEvent :: appSession[{}], ASR[{}]", appSession, asr); } public void doAbortSessionAnswerEvent(ServerAuthSession appSession, AbortSessionAnswer asa) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doAbortSessionAnswerEvent :: appSession[{}], ASA[{}]", appSession, asa); } public void doSessionTerminationRequestEvent(ServerAuthSession appSession, SessionTermRequest str) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doSessionTerminationRequestEvent :: appSession[{}], STR[{}]", appSession, str); } public void doSessionTerminationAnswerEvent(ClientAuthSession appSession, SessionTermAnswer sta) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doSessionTerminationAnswerEvent :: appSession[{}], STA[{}]", appSession, sta); } public void doAuthRequestEvent(ServerAuthSession appSession, AppRequestEvent request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doAuthRequestEvent :: appSession[{}], Request[{}]", appSession, request); } public void doAuthAnswerEvent(ClientAuthSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doAuthAnswerEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } public void doReAuthRequestEvent(ClientAuthSession appSession, ReAuthRequest rar) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doReAuthRequestEvent :: appSession[{}], RAR[{}]", appSession, rar); } public void doReAuthAnswerEvent(ServerAuthSession appSession, ReAuthRequest rar, ReAuthAnswer raa) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doReAuthAnswerEvent :: appSession[{}], RAR[{}], RAA[{}]", new Object[]{appSession, rar, raa}); } public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AuthorizationSessionFactory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } // State Change Listener -------------------------------------------------- @SuppressWarnings("unchecked") public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter Base AuthorizationSessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ @SuppressWarnings("unchecked") public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Base AuthorizationSessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[] {source, oldState, newState}); } // Context Methods -------------------------------------------------------- /* * (non-Javadoc) * * @seeorg.jdiameter.common.api.app.auth.IClientAuthActionContext#accessTimeoutElapses(org.jdiameter.api.auth.ClientAuthSession) */ public void accessTimeoutElapses(ClientAuthSession session) throws InternalException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.auth.IClientAuthActionContext#createAccessTimer() */ public long getAccessTimeout() throws InternalException { return 20000; } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.auth.IClientAuthActionContext#disconnectUserOrDev(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.Message) */ public void disconnectUserOrDev(ClientAuthSession session, Message request) throws InternalException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @seeorg.jdiameter.common.api.app.auth.IServerAuthActionContext# * accessTimeoutElapses(org.jdiameter.api.auth.ServerAuthSession) */ public void accessTimeoutElapses(ServerAuthSession session) throws InternalException { // TODO Auto-generated method stub } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.auth.events.SessionTermAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class SessionTermAnswerImpl extends AppAnswerEventImpl implements SessionTermAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public SessionTermAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public SessionTermAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public SessionTermAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public SessionTermAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.Request; import org.jdiameter.api.auth.events.AbortSessionAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AbortSessionAnswerImpl extends AppAnswerEventImpl implements AbortSessionAnswer { private static final long serialVersionUID = 1L; public AbortSessionAnswerImpl(Request request, int authRequestType, long resultCode) { super(request.createAnswer(resultCode)); try { getMessage().getAvps().addAvp(Avp.AUTH_REQUEST_TYPE, authRequestType); } catch (Exception e) { throw new IllegalArgumentException(e); } } /** * @param answer */ public AbortSessionAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public AbortSessionAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public AbortSessionAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public AbortSessionAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import static org.jdiameter.api.Avp.AUTH_APPLICATION_ID; import static org.jdiameter.api.Avp.TERMINATION_CAUSE; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Message; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.auth.events.SessionTermRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class SessionTermRequestImpl extends AppRequestEventImpl implements SessionTermRequest { private static final long serialVersionUID = 1L; public SessionTermRequestImpl(AppSession session, int terminationCause, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); message.getAvps().addAvp(Avp.TERMINATION_CAUSE, terminationCause, true, false); } public SessionTermRequestImpl(Message message) { super(message); } public long getAuthApplicationId() throws AvpDataException { Avp authApplicationIdAvp = message.getAvps().getAvp(AUTH_APPLICATION_ID); if (authApplicationIdAvp != null) { return authApplicationIdAvp.getUnsigned32(); } else { throw new AvpDataException("Avp AUTH_APPLICATION_ID not found"); } } public int getTerminationCause() throws AvpDataException { Avp terminationCauseAvp = message.getAvps().getAvp(TERMINATION_CAUSE); if (terminationCauseAvp != null) { return terminationCauseAvp.getInteger32(); } else { throw new AvpDataException("Avp TERMINATION_CAUSE not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.auth.IAuthSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public abstract class AppAuthSessionImpl extends AppSessionImpl implements NetworkReqListener, org.jdiameter.api.app.StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); protected ApplicationId appId; protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); // protected SessionFactory sf = null; public AppAuthSessionImpl(ISessionFactory sf, IAuthSessionData sessionData) { super(sf, sessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public void release() { //stateListeners.clear(); super.release(); } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((appId == null) ? 0 : appId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; AppAuthSessionImpl other = (AppAuthSessionImpl) obj; if (appId == null) { if (other.appId != null) return false; } else if (!appId.equals(other.appId)) return false; return true; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import static org.jdiameter.api.Avp.AUTH_APPLICATION_ID; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Message; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.auth.events.AbortSessionRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AbortSessionRequestImpl extends AppRequestEventImpl implements AbortSessionRequest { private static final long serialVersionUID = 1L; public AbortSessionRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public AbortSessionRequestImpl(Message message) { super(message); } public long getAuthApplicationId() throws AvpDataException { Avp authApplicationIdAvp = message.getAvps().getAvp(AUTH_APPLICATION_ID); if (authApplicationIdAvp != null) { return authApplicationIdAvp.getUnsigned32(); } else { throw new AvpDataException("Avp AUTH_APPLICATION_ID not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.auth.ClientAuthSession; import org.jdiameter.api.auth.ServerAuthSession; import org.jdiameter.client.impl.app.auth.ClientAuthSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.auth.IAuthSessionData; import org.jdiameter.server.impl.app.auth.ServerAuthSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AuthLocalSessionDataFactory implements IAppSessionDataFactory<IAuthSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IAuthSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientAuthSession.class)) { ClientAuthSessionDataLocalImpl data = new ClientAuthSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerAuthSession.class)) { ServerAuthSessionDataLocalImpl data = new ServerAuthSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.auth; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.auth.events.ReAuthAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class ReAuthAnswerImpl extends AppAnswerEventImpl implements ReAuthAnswer { private static final long serialVersionUID = 1L; /** * @param answer */ public ReAuthAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public ReAuthAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public ReAuthAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public ReAuthAnswerImpl(Request request) { super(request); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.acc; import java.util.concurrent.ScheduledFuture; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.IllegalDiameterStateException; import org.jdiameter.api.InternalException; import org.jdiameter.api.OverloadException; import org.jdiameter.api.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.acc.ClientAccSession; import org.jdiameter.api.acc.ClientAccSessionListener; import org.jdiameter.api.acc.ServerAccSession; import org.jdiameter.api.acc.ServerAccSessionListener; import org.jdiameter.api.acc.events.AccountAnswer; import org.jdiameter.api.acc.events.AccountRequest; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.acc.ClientAccSessionImpl; import org.jdiameter.client.impl.app.acc.IClientAccSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.acc.IAccMessageFactory; import org.jdiameter.common.api.app.acc.IAccSessionData; import org.jdiameter.common.api.app.acc.IAccSessionFactory; import org.jdiameter.common.api.app.acc.IClientAccActionContext; import org.jdiameter.common.api.app.acc.IServerAccActionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.server.impl.app.acc.IServerAccSessionData; import org.jdiameter.server.impl.app.acc.ServerAccSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Account Session Factory implementation * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AccSessionFactoryImpl implements IAccSessionFactory,IAccMessageFactory, ServerAccSessionListener, ClientAccSessionListener, IClientAccActionContext, IServerAccActionContext, StateChangeListener<AppSession> { protected Logger logger = LoggerFactory.getLogger(AccSessionFactoryImpl.class); protected ServerAccSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected ClientAccSessionListener clientSessionListener; protected IClientAccActionContext clientContextListener; protected IServerAccActionContext serverContextListener; protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected ApplicationId applicationId; protected IAccMessageFactory messageFactory = this; protected IAppSessionDataFactory<IAccSessionData> sessionDataFactory; protected AccSessionFactoryImpl() { } public AccSessionFactoryImpl(SessionFactory sessionFactory) { super(); setSessionFactory((ISessionFactory) sessionFactory); } // ACC Factory Methods ------------------------------------------------------ /** * @return the serverSessionListener */ public ServerAccSessionListener getServerSessionListener() { if (this.serverSessionListener != null) { return serverSessionListener; } else { return this; } } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerAccSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { if (this.stateListener != null) { return stateListener; } else { return this; } } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } /** * @return the clientSessionListener */ public ClientAccSessionListener getClientSessionListener() { if (this.clientSessionListener != null) { return clientSessionListener; } else { return this; } } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(ClientAccSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the clientContextListener */ public IClientAccActionContext getClientContextListener() { if (this.clientContextListener != null) { return clientContextListener; } else { return this; } } /** * @param clientContextListener * the clientContextListener to set */ public void setClientContextListener(IClientAccActionContext clientContextListener) { this.clientContextListener = clientContextListener; } /** * @return the serverContextListener */ public IServerAccActionContext getServerContextListener() { if (this.serverContextListener != null) { return serverContextListener; } else { return this; } } /** * @param serverContextListener * the serverContextListener to set */ public void setServerContextListener(IServerAccActionContext serverContextListener) { this.serverContextListener = serverContextListener; } public void setMessageFactory(IAccMessageFactory messageFactory) { this.messageFactory = messageFactory; } public IAccMessageFactory getMessageFactory() { return this.messageFactory; } /** * @return the sessionFactory */ public ISessionFactory getSessionFactory() { return sessionFactory; } /** * @param sessionFactory the sessionFactory to set */ public void setSessionFactory(ISessionFactory sessionFactory) { this.sessionFactory = sessionFactory; if (this.iss == null) { this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IAccSessionData>) this.iss.getDataFactory(IAccSessionData.class); if (this.sessionDataFactory == null) { logger.debug("No factory for Accounting Application data, using default/local."); this.sessionDataFactory = new AccLocalSessionDataFactory(); } } } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IAccSessionFactory#getApplicationId() */ public ApplicationId getApplicationId() { return this.applicationId; } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IAccSessionFactory#setApplicationId( org.jdiameter.api.ApplicationId) */ public void setApplicationId(ApplicationId id) { this.applicationId = id; } // App Session Factory ------------------------------------------------------ @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if(!this.iss.exists(sessionId)) { return null; } AppSession appSession = null; try { if (aClass == ClientAccSession.class) { IClientAccSessionData data = (IClientAccSessionData) this.sessionDataFactory.getAppSessionData(ClientAccSession.class, sessionId); ClientAccSessionImpl clientSession = new ClientAccSessionImpl(data, sessionFactory, getClientSessionListener(), getClientContextListener(), getStateListener()); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerAccSession.class) { ServerAccSessionImpl serverSession = null; IServerAccSessionData data = (IServerAccSessionData) this.sessionDataFactory.getAppSessionData(ServerAccSession.class, sessionId); //here we use shorter con, since some data is already present. serverSession = new ServerAccSessionImpl(data,sessionFactory, getServerSessionListener(), getServerContextListener(), getStateListener()); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientAccSession.class + "," + ServerAccSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Accounting Session.", e); } return appSession; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { try { if (aClass == ServerAccSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } boolean stateless = true; if(args != null && args.length > 0) { for(Object o:args) { if(o instanceof Boolean) { stateless = (Boolean)o; } } } IServerAccSessionData data = (IServerAccSessionData) this.sessionDataFactory.getAppSessionData(ServerAccSession.class, sessionId); data.setApplicationId(applicationId); ServerAccSessionImpl session = new ServerAccSessionImpl(data, sessionFactory, getServerSessionListener(), getServerContextListener(), getStateListener(), stateless); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } else if (aClass == ClientAccSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientAccSessionData data = (IClientAccSessionData) this.sessionDataFactory.getAppSessionData(ClientAccSession.class, sessionId); data.setApplicationId(applicationId); ClientAccSessionImpl session = new ClientAccSessionImpl(data, sessionFactory, getClientSessionListener(), getClientContextListener(), getStateListener()); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } } catch (Exception e) { logger.error("Failure to obtain new Accounting Session.", e); } return null; } // State Change Listener ---------------------------------------------------- public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter ACC SessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter ACC SessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[] { source, oldState, newState }); } // /////////////////// // Event listeners // // /////////////////// public void doAccRequestEvent(ServerAccSession appSession, AccountRequest acr) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AccountingSessionFactory :: doAccRequestEvent :: appSession[" + appSession + "], Request[" + acr + "]"); } public void doAccAnswerEvent(ClientAccSession appSession, AccountRequest acr, AccountAnswer aca) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("doAccAnswerEvent :: appSession[" + appSession + "], Request[" + acr + "], Answer[" + aca + "]"); } public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base AccountingSessionFactory :: doOtherEvent :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]"); } // Client context ----------------------------------------------------------- /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IClientAccActionContext#disconnectUserOrDev (org.jdiameter.api.Request) */ public void disconnectUserOrDev(ClientAccSession appSession, Request sessionTermRequest) throws InternalException { logger.info("disconnectUserOrDev :: appSession[" + appSession + "], Request[" + sessionTermRequest + "]"); } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IClientAccActionContext#failedSendRecord (org.jdiameter.api.Request) */ public boolean failedSendRecord(ClientAccSession appSession, Request accRequest) throws InternalException { logger.info("failedSendRecord :: appSession[" + appSession + "], Request[" + accRequest + "]"); return false; } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IClientAccActionContext# interimIntervalElapses(org.jdiameter.api.Request) */ public void interimIntervalElapses(ClientAccSession appSession, Request interimRequest) throws InternalException { logger.info("interimIntervalElapses :: appSession[" + appSession + "], Request[" + interimRequest + "]"); } // Server context ----------------------------------------------------------- /* * (non-Javadoc) * * @seeorg.jdiameter.common.api.app.acc.IServerAccActionContext#sessionTimeoutElapses(org.jdiameter.api.acc.ServerAccSession) */ public void sessionTimeoutElapses(ServerAccSession appSession) throws InternalException { logger.info("sessionTimeoutElapses :: appSession[" + appSession + "]"); } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IServerAccActionContext#sessionTimerStarted(org.jdiameter.api.acc.ServerAccSession, java.util.concurrent.ScheduledFuture) */ @SuppressWarnings("unchecked") public void sessionTimerStarted(ServerAccSession appSession, ScheduledFuture timer) throws InternalException { logger.info("sessionTimerStarted :: appSession[" + appSession + "]"); } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IServerAccActionContext#srssionTimerCanceled(org.jdiameter.api.acc.ServerAccSession, java.util.concurrent.ScheduledFuture) */ @SuppressWarnings("unchecked") public void sessionTimerCanceled(ServerAccSession appSession, ScheduledFuture timer) throws InternalException { logger.info("sessionTimerCanceled :: appSession[" + appSession + "]"); } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.acc.IAccMessageFactory#getAccMessageCommandCode * () */ @Override public int getAccMessageCommandCode() { // TODO Auto-generated method stub return AccountRequest.code; } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.acc.IAccMessageFactory#createAccRequest( * org.jdiameter.api.Request) */ @Override public AccountRequest createAccRequest(Request request) { return new AccountRequestImpl(request); } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.acc.IAccMessageFactory#createAccAnswer(org * .jdiameter.api.Answer) */ @Override public AccountAnswer createAccAnswer(Answer answer) { return new AccountAnswerImpl(answer); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.acc; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.Answer; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.Request; import org.jdiameter.api.acc.events.AccountAnswer; import org.jdiameter.api.acc.events.AccountRequest; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.IAppSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public abstract class AppAccSessionImpl extends AppSessionImpl implements NetworkReqListener, org.jdiameter.api.app.StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); public AppAccSessionImpl(ISessionFactory sf, IAppSessionData appSessionData) { super(sf, appSessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } protected AccountRequest createAccountRequest(Request request) { return new AccountRequestImpl(request); } protected AccountAnswer createAccountAnswer(Answer answer) { return new AccountAnswerImpl(answer); } public void release() { //stateListeners.clear(); super.release(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.acc; import static org.jdiameter.api.Avp.ACC_RECORD_NUMBER; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.acc.events.AccountAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * erick.svenson@yahoo.com * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AccountAnswerImpl extends AppAnswerEventImpl implements AccountAnswer { private static final long serialVersionUID = 1L; public AccountAnswerImpl(Request request, int accountRecordType, int accReqNumber, long resultCode) { this(request.createAnswer(resultCode)); try { getMessage().getAvps().addAvp(Avp.ACC_RECORD_TYPE, accountRecordType); getMessage().getAvps().addAvp(Avp.ACC_RECORD_NUMBER, accReqNumber); } catch (Exception e) { throw new IllegalArgumentException(e); } } /** * @param answer */ public AccountAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public AccountAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public AccountAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public AccountAnswerImpl(Request request) { super(request); } public int getAccountingRecordType() throws AvpDataException { Avp accRecordTypeAvp = message.getAvps().getAvp(Avp.ACC_RECORD_TYPE); if (accRecordTypeAvp != null) { return accRecordTypeAvp.getInteger32(); } else { throw new AvpDataException("Avp ACC_RECORD_TYPE not found"); } } public long getAccountingRecordNumber() throws AvpDataException { Avp accRecordNumberAvp = message.getAvps().getAvp(ACC_RECORD_NUMBER); if (accRecordNumberAvp != null) { return accRecordNumberAvp.getUnsigned32(); } else { throw new AvpDataException("Avp ACC_RECORD_NUMBER not found"); } } }
Java
/* /* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app.acc; import static org.jdiameter.api.Avp.ACC_RECORD_NUMBER; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.acc.events.AccountRequest; import org.jdiameter.api.app.AppSession; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AccountRequestImpl extends AppRequestEventImpl implements AccountRequest { private static final long serialVersionUID = 1L; public AccountRequestImpl(AppSession session, int accountRecordType, int accReqNumber, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); try { getMessage().getAvps().addAvp(Avp.ACC_RECORD_TYPE, accountRecordType); getMessage().getAvps().addAvp(Avp.ACC_RECORD_NUMBER, accReqNumber); } catch (Exception e) { throw new IllegalArgumentException(e); } } public AccountRequestImpl(Request request) { super(request); } public int getAccountingRecordType() throws AvpDataException { Avp accRecordTypeAvp = message.getAvps().getAvp(Avp.ACC_RECORD_TYPE); if (accRecordTypeAvp != null) { return accRecordTypeAvp.getInteger32(); } else { throw new AvpDataException("Avp ACC_RECORD_TYPE not found"); } } public long getAccountingRecordNumber() throws AvpDataException { Avp accRecordNumberAvp = message.getAvps().getAvp(ACC_RECORD_NUMBER); if (accRecordNumberAvp != null) { return accRecordNumberAvp.getUnsigned32(); } else { throw new AvpDataException("Avp ACC_RECORD_NUMBER not found"); } } public void setAccountingRecordType(int recordType) throws AvpDataException { message.getAvps().removeAvp(Avp.ACC_RECORD_TYPE); message.getAvps().addAvp(Avp.ACC_RECORD_TYPE, recordType); } public void setAccountingRecordNumber(long recordNum) throws AvpDataException { message.getAvps().removeAvp(Avp.ACC_RECORD_NUMBER); message.getAvps().addAvp(Avp.ACC_RECORD_NUMBER, ACC_RECORD_NUMBER, true); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.app.acc; import org.jdiameter.api.acc.ClientAccSession; import org.jdiameter.api.acc.ServerAccSession; import org.jdiameter.api.app.AppSession; import org.jdiameter.client.impl.app.acc.ClientAccSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.acc.IAccSessionData; import org.jdiameter.server.impl.app.acc.ServerAccSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AccLocalSessionDataFactory implements IAppSessionDataFactory<IAccSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IAccSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientAccSession.class)) { ClientAccSessionDataLocalImpl data = new ClientAccSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerAccSession.class)) { ServerAccSessionDataLocalImpl data = new ServerAccSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * 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.jdiameter.common.impl.app.gq; import org.jdiameter.api.Answer; 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.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.gq.GqClientSession; import org.jdiameter.api.gq.GqServerSession; import org.jdiameter.api.auth.ClientAuthSession; import org.jdiameter.api.auth.ServerAuthSession; import org.jdiameter.api.auth.ClientAuthSessionListener; import org.jdiameter.api.auth.ServerAuthSessionListener; import org.jdiameter.api.auth.events.AbortSessionAnswer; import org.jdiameter.api.auth.events.AbortSessionRequest; import org.jdiameter.api.auth.events.ReAuthAnswer; import org.jdiameter.api.auth.events.ReAuthRequest; import org.jdiameter.api.auth.events.SessionTermAnswer; import org.jdiameter.api.auth.events.SessionTermRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.gq.GqClientSessionImpl; import org.jdiameter.client.impl.app.auth.IClientAuthSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.auth.IAuthMessageFactory; import org.jdiameter.common.api.app.auth.IAuthSessionData; import org.jdiameter.common.api.app.auth.IAuthSessionFactory; import org.jdiameter.common.api.app.auth.IClientAuthActionContext; import org.jdiameter.common.api.app.auth.IServerAuthActionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.jdiameter.server.impl.app.auth.IServerAuthSessionData; import org.jdiameter.server.impl.app.gq.GqServerSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Gq Application Session Factory implementation * * @author <a href="mailto:webdev@web-ukraine.info"> Yulian Oifa </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class GqSessionFactoryImpl implements IAuthSessionFactory, IAuthMessageFactory, ServerAuthSessionListener, ClientAuthSessionListener, IClientAuthActionContext, IServerAuthActionContext, StateChangeListener<AppSession> { private final static long authAppId = 16777222L; protected IAuthMessageFactory messageFactory; protected ServerAuthSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected ClientAuthSessionListener clientSessionListener; protected boolean stateles; protected long messageTimeout = 5000; protected Logger logger = LoggerFactory.getLogger(GqSessionFactoryImpl.class); protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected IServerAuthActionContext serverSessionContext; protected IClientAuthActionContext clientSessionContext; protected IAppSessionDataFactory<IAuthSessionData> sessionDataFactory; public GqSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IAuthSessionData>) this.iss.getDataFactory(IAuthSessionData.class); } /** * @return the clientSessionContext */ public IClientAuthActionContext getClientSessionContext() { return clientSessionContext != null ? clientSessionContext : this; } /** * @param clientSessionContext * the clientSessionContext to set */ public void setClientSessionContext(IClientAuthActionContext clientSessionContext) { this.clientSessionContext = clientSessionContext; } /** * @return the serverSessionContext */ public IServerAuthActionContext getServerSessionContext() { return serverSessionContext != null ? serverSessionContext : this; } /** * @param serverSessionContext * the serverSessionContext to set */ public void setServerSessionContext(IServerAuthActionContext serverSessionContext) { this.serverSessionContext = serverSessionContext; } /** * @return the messageTimeout */ public long getMessageTimeout() { return messageTimeout; } /** * @param messageTimeout * the messageTimeout to set */ public void setMessageTimeout(long messageTimeout) { this.messageTimeout = messageTimeout; } /** * @return the messageFactory */ public IAuthMessageFactory getMessageFactory() { return messageFactory != null ? messageFactory : this; } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(IAuthMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @return the serverSessionListener */ public ServerAuthSessionListener getServerSessionListener() { return serverSessionListener != null ? serverSessionListener : this; } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerAuthSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { return stateListener != null ? stateListener : this; } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } /** * @return the clientSessionListener */ public ClientAuthSessionListener getClientSessionListener() { return clientSessionListener != null ? clientSessionListener : this; } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(ClientAuthSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } public boolean isStateles() { return stateles; } public void setStateles(boolean stateles) { this.stateles = stateles; } @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if(!this.iss.exists(sessionId)) { return null; } try { if (aClass == GqServerSession.class) { IServerAuthSessionData sessionData = (IServerAuthSessionData) this.sessionDataFactory.getAppSessionData(GqServerSession.class, sessionId); GqServerSessionImpl session = new GqServerSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getMessageFactory(), getStateListener(), getServerSessionContext(), messageTimeout, isStateles()); session.getSessions().get(0).setRequestListener(session); return session; } else { if (aClass == GqClientSession.class) { IClientAuthSessionData sessionData = (IClientAuthSessionData) this.sessionDataFactory.getAppSessionData(GqClientSession.class, sessionId); GqClientSessionImpl session = new GqClientSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getMessageFactory(), getStateListener(), getClientSessionContext(), isStateles()); session.getSessions().get(0).setRequestListener(session); return session; } } } catch (Exception e) { logger.error("Failure trying to obtain new authorization session", e); } return null; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { try { if (aClass == GqServerSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerAuthSessionData sessionData = (IServerAuthSessionData) this.sessionDataFactory.getAppSessionData(ServerAuthSession.class, sessionId); sessionData.setApplicationId(applicationId); GqServerSessionImpl session = new GqServerSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getMessageFactory(), getStateListener(), getServerSessionContext(), messageTimeout, isStateles()); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } else { if (aClass == GqClientSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientAuthSessionData sessionData = (IClientAuthSessionData) this.sessionDataFactory.getAppSessionData(ClientAuthSession.class, sessionId); sessionData.setApplicationId(applicationId); GqClientSessionImpl session = new GqClientSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getMessageFactory(), getStateListener(), getClientSessionContext(), isStateles()); iss.addSession(session); // iss.setSessionListener(clientSession.getSessionId(), (NetworkReqListener) appSession); session.getSessions().get(0).setRequestListener(session); return session; } } } catch (Exception e) { logger.error("Failure trying to obtain new authorization session", e); } return null; } // Message Factory Methods ------------------------------------------------ public AppAnswerEvent createAuthAnswer(Answer answer) { return new AppAnswerEventImpl(answer); } public AppRequestEvent createAuthRequest(Request request) { return new AppRequestEventImpl(request); } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.auth.IAuthMessageFactory#getAuthMessageCommandCode() */ public int getAuthMessageCommandCode() { return 265; } public ApplicationId getApplicationId() { return ApplicationId.createByAuthAppId(authAppId); } // Message Handlers ------------------------------------------------------- /* (non-Javadoc) * @see org.jdiameter.api.auth.ClientAuthSessionListener#doAbortSessionRequestEvent(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.auth.events.AbortSessionRequest) */ public void doAbortSessionRequestEvent(ClientAuthSession appSession, AbortSessionRequest asr) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doAbortSessionRequestEvent :: appSession[{}], ASR[{}]", appSession, asr); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ServerAuthSessionListener#doAbortSessionAnswerEvent(org.jdiameter.api.auth.ServerAuthSession, org.jdiameter.api.auth.events.AbortSessionAnswer) */ public void doAbortSessionAnswerEvent(ServerAuthSession appSession, AbortSessionAnswer asa) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doAbortSessionAnswerEvent :: appSession[{}], ASA[{}]", appSession, asa); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ServerAuthSessionListener#doSessionTerminationRequestEvent(org.jdiameter.api.auth.ServerAuthSession, org.jdiameter.api.auth.events.SessionTermRequest) */ public void doSessionTerminationRequestEvent(ServerAuthSession appSession, SessionTermRequest str) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doSessionTerminationRequestEvent :: appSession[{}], STR[{}]", appSession, str); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ClientAuthSessionListener#doSessionTerminationAnswerEvent(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.auth.events.SessionTermAnswer) */ public void doSessionTerminationAnswerEvent(ClientAuthSession appSession, SessionTermAnswer sta) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doSessionTerminationAnswerEvent :: appSession[{}], STA[{}]", appSession, sta); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ServerAuthSessionListener#doAuthRequestEvent(org.jdiameter.api.auth.ServerAuthSession, org.jdiameter.api.app.AppRequestEvent) */ public void doAuthRequestEvent(ServerAuthSession appSession, AppRequestEvent request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doAuthRequestEvent :: appSession[{}], Request[{}]", appSession, request); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ClientAuthSessionListener#doAuthAnswerEvent(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.app.AppRequestEvent, org.jdiameter.api.app.AppAnswerEvent) */ public void doAuthAnswerEvent(ClientAuthSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doAuthAnswerEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ClientAuthSessionListener#doReAuthRequestEvent(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.auth.events.ReAuthRequest) */ public void doReAuthRequestEvent(ClientAuthSession appSession, ReAuthRequest rar) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doReAuthRequestEvent :: appSession[{}], RAR[{}]", appSession, rar); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ServerAuthSessionListener#doReAuthAnswerEvent(org.jdiameter.api.auth.ServerAuthSession, org.jdiameter.api.auth.events.ReAuthRequest, org.jdiameter.api.auth.events.ReAuthAnswer) */ public void doReAuthAnswerEvent(ServerAuthSession appSession, ReAuthRequest rar, ReAuthAnswer raa) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doReAuthAnswerEvent :: appSession[{}], RAR[{}], RAA[{}]", new Object[]{appSession, rar, raa}); } /* (non-Javadoc) * @see org.jdiameter.api.auth.ServerAuthSessionListener#doOtherEvent(org.jdiameter.api.app.AppSession, org.jdiameter.api.app.AppRequestEvent, org.jdiameter.api.app.AppAnswerEvent) */ public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Gq AuthorizationSessionFactory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer}); } // State Change Listener -------------------------------------------------- /* (non-Javadoc) * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Enum, java.lang.Enum) */ public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter Gq AuthorizationSessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* (non-Javadoc) * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Gq AuthorizationSessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[] {source, oldState, newState}); } // Context Methods -------------------------------------------------------- /* (non-Javadoc) * @see org.jdiameter.common.api.app.auth.IClientAuthActionContext#accessTimeoutElapses(org.jdiameter.api.auth.ClientAuthSession) */ public void accessTimeoutElapses(ClientAuthSession session) throws InternalException { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.jdiameter.common.api.app.auth.IClientAuthActionContext#getAccessTimeout() */ public long getAccessTimeout() throws InternalException { return 20000; } /* (non-Javadoc) * @see org.jdiameter.common.api.app.auth.IClientAuthActionContext#disconnectUserOrDev(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.Message) */ public void disconnectUserOrDev(ClientAuthSession session, Message request) throws InternalException { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.jdiameter.common.api.app.auth.IServerAuthActionContext#accessTimeoutElapses(org.jdiameter.api.auth.ServerAuthSession) */ public void accessTimeoutElapses(ServerAuthSession session) throws InternalException { // TODO Auto-generated method stub } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2006, 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.jdiameter.common.impl.app; import static org.jdiameter.api.Avp.DESTINATION_HOST; import static org.jdiameter.api.Avp.DESTINATION_REALM; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Message; import org.jdiameter.api.app.AppRequestEvent; /** * * @author erick.svenson@yahoo.com * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class AppRequestEventImpl extends AppEventImpl implements AppRequestEvent { private static final long serialVersionUID = 1L; public AppRequestEventImpl(Message message) { super(message); } public String getDestinationHost() throws AvpDataException { Avp destHostAvp = message.getAvps().getAvp(DESTINATION_HOST); if (destHostAvp != null) { return destHostAvp.getDiameterIdentity(); } else { throw new AvpDataException("Avp DESTINATION_HOST not found"); } } public String getDestinationRealm() throws AvpDataException { Avp destRealmAvp = message.getAvps().getAvp(DESTINATION_REALM); if (destRealmAvp != null) { return destRealmAvp.getDiameterIdentity(); } else { throw new AvpDataException("Avp DESTINATION_REALM not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.ro; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.ro.events.RoCreditControlRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * ... * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class RoCreditControlRequestImpl extends AppRequestEventImpl implements RoCreditControlRequest { private static final long serialVersionUID = 1L; protected Logger logger = LoggerFactory.getLogger(RoCreditControlRequestImpl.class); private static final int REQUESTED_ACTION_AVP_CODE = 436; private static final int CC_REQUEST_TYPE_AVP_CODE = 416; public RoCreditControlRequestImpl(AppSession session, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); } public RoCreditControlRequestImpl(Request request) { super(request); } public boolean isRequestedActionAVPPresent() { return super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE) != null; } public int getRequestedActionAVPValue() { Avp requestedActionAvp = super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE); if(requestedActionAvp != null) { try { return requestedActionAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Requested-Action AVP value", e); } } return -1; } public boolean isRequestTypeAVPPresent() { return super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE) != null; } public int getRequestTypeAVPValue() { Avp requestTypeAvp = super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE); if(requestTypeAvp != null) { try { return requestTypeAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain CC-Request-Type AVP value", e); } } return -1; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.ro; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.ro.events.RoCreditControlAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; import org.slf4j.Logger; /** * ... * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class RoCreditControlAnswerImpl extends AppAnswerEventImpl implements RoCreditControlAnswer { private static final long serialVersionUID = 1L; protected Logger logger = org.slf4j.LoggerFactory.getLogger(RoCreditControlAnswerImpl.class); private static final int CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE = 427; private static final int DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE = 428; private static final int REQUESTED_ACTION_AVP_CODE = 436; private static final int CC_REQUEST_TYPE_AVP_CODE = 416; private static final int VALIDITY_TIME_AVP_CODE = 448; /** * @param answer */ public RoCreditControlAnswerImpl(Answer answer) { super(answer); } /** * @param request * @param vendorId * @param resultCode */ public RoCreditControlAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public RoCreditControlAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public RoCreditControlAnswerImpl(Request request) { super(request); } public boolean isCreditControlFailureHandlingAVPPresent() { return super.message.getAvps().getAvp(CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE) != null; } public int getCredidControlFailureHandlingAVPValue() { Avp credidControlFailureHandlingAvp = super.message.getAvps().getAvp(CREDIT_CONTROL_FAILURE_HANDLING_AVP_CODE); if(credidControlFailureHandlingAvp != null) { try { return credidControlFailureHandlingAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Credit-Control-Failure-Handling AVP value", e); } } return -1; } public boolean isDirectDebitingFailureHandlingAVPPresent() { return super.message.getAvps().getAvp(DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE) != null; } public int getDirectDebitingFailureHandlingAVPValue() { Avp directDebitingFailureHandlingAvp = super.message.getAvps().getAvp(DIRECT_DEBITING_FAILURE_HANDLING_AVP_CODE); if(directDebitingFailureHandlingAvp != null) { try { return directDebitingFailureHandlingAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Direct-Debiting-Failure-Handling AVP value", e); } } return -1; } public Avp getValidityTimeAvp() { return super.message.getAvps().getAvp(VALIDITY_TIME_AVP_CODE); } public boolean isRequestTypeAVPPresent() { return super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE) != null; } public int getRequestTypeAVPValue() { Avp requestTypeAvp = super.message.getAvps().getAvp(CC_REQUEST_TYPE_AVP_CODE); if(requestTypeAvp != null) { try { return requestTypeAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain CC-Request-Type AVP value", e); } } return -1; } public boolean isRequestedActionAVPPresent() { return super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE) != null; } public int getRequestedActionAVPValue() { Avp requestedActionAvp = super.message.getAvps().getAvp(REQUESTED_ACTION_AVP_CODE); if(requestedActionAvp != null) { try { return requestedActionAvp.getInteger32(); } catch (AvpDataException e) { logger.debug("Failure trying to obtain Requested-Action AVP value", e); } } return -1; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.ro; import java.util.concurrent.ScheduledFuture; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.InternalException; import org.jdiameter.api.Message; import org.jdiameter.api.Request; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.auth.events.ReAuthAnswer; import org.jdiameter.api.auth.events.ReAuthRequest; import org.jdiameter.api.ro.ClientRoSession; import org.jdiameter.api.ro.ClientRoSessionListener; import org.jdiameter.api.ro.ServerRoSession; import org.jdiameter.api.ro.ServerRoSessionListener; import org.jdiameter.api.ro.events.RoCreditControlAnswer; import org.jdiameter.api.ro.events.RoCreditControlRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.ro.ClientRoSessionImpl; import org.jdiameter.client.impl.app.ro.IClientRoSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.ro.IClientRoSessionContext; import org.jdiameter.common.api.app.ro.IRoMessageFactory; import org.jdiameter.common.api.app.ro.IRoSessionData; import org.jdiameter.common.api.app.ro.IRoSessionFactory; import org.jdiameter.common.api.app.ro.IServerRoSessionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.common.impl.app.auth.ReAuthAnswerImpl; import org.jdiameter.common.impl.app.auth.ReAuthRequestImpl; import org.jdiameter.server.impl.app.ro.IServerRoSessionData; import org.jdiameter.server.impl.app.ro.ServerRoSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Ro Session Factory implementation * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RoSessionFactoryImpl implements IRoSessionFactory, ClientRoSessionListener, ServerRoSessionListener, StateChangeListener<AppSession>, IRoMessageFactory, IServerRoSessionContext, IClientRoSessionContext { // Message timeout value (in milliseconds) protected int defaultDirectDebitingFailureHandling = 0; protected int defaultCreditControlFailureHandling = 0; // its seconds protected long defaultValidityTime = 60; protected long defaultTxTimerValue = 30; // local not replicated listeners: protected ClientRoSessionListener clientSessionListener; protected ServerRoSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected IServerRoSessionContext serverContextListener; protected IClientRoSessionContext clientContextListener; protected IRoMessageFactory messageFactory; protected Logger logger = LoggerFactory.getLogger(RoSessionFactoryImpl.class); protected ISessionDatasource iss; protected IAppSessionDataFactory<IRoSessionData> sessionDataFactory; protected ISessionFactory sessionFactory = null; public RoSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IRoSessionData>) this.iss.getDataFactory(IRoSessionData.class); } public RoSessionFactoryImpl(SessionFactory sessionFactory, int defaultDirectDebitingFailureHandling, int defaultCreditControlFailureHandling, long defaultValidityTime, long defaultTxTimerValue) { this(sessionFactory); this.defaultDirectDebitingFailureHandling = defaultDirectDebitingFailureHandling; this.defaultCreditControlFailureHandling = defaultCreditControlFailureHandling; this.defaultValidityTime = defaultValidityTime; this.defaultTxTimerValue = defaultTxTimerValue; } /** * @return the clientSessionListener */ public ClientRoSessionListener getClientSessionListener() { if (clientSessionListener != null) { return clientSessionListener; } else { return this; } } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(ClientRoSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the serverSessionListener */ public ServerRoSessionListener getServerSessionListener() { if (serverSessionListener != null) { return serverSessionListener; } else { return this; } } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerRoSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the serverContextListener */ public IServerRoSessionContext getServerContextListener() { if (serverContextListener != null) { return serverContextListener; } else { return this; } } /** * @param serverContextListener * the serverContextListener to set */ public void setServerContextListener(IServerRoSessionContext serverContextListener) { this.serverContextListener = serverContextListener; } /** * @return the clientContextListener */ public IClientRoSessionContext getClientContextListener() { if (clientContextListener != null) { return clientContextListener; } else { return this; } } /** * @return the messageFactory */ public IRoMessageFactory getMessageFactory() { if (messageFactory != null) { return messageFactory; } else { return this; } } /** * @param messageFactory * the messageFactory to set */ public void setMessageFactory(IRoMessageFactory messageFactory) { this.messageFactory = messageFactory; } /** * @param clientContextListener * the clientContextListener to set */ public void setClientContextListener(IClientRoSessionContext clientContextListener) { this.clientContextListener = clientContextListener; } /** * @return the sessionFactory */ public SessionFactory getSessionFactory() { return sessionFactory; } /** * @param sessionFactory * the sessionFactory to set */ public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = (ISessionFactory) sessionFactory; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { if (this.stateListener != null) { return stateListener; } else { return this; } } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { AppSession appSession = null; try { //TODO:check for existence if (aClass == ClientRoSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } ClientRoSessionImpl clientSession = null; IClientRoSessionData sessionData = (IClientRoSessionData) this.sessionDataFactory.getAppSessionData(ClientRoSession.class, sessionId); sessionData.setApplicationId(applicationId); clientSession = new ClientRoSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); // this goes first! iss.addSession(clientSession); clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerRoSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerRoSessionData sessionData = (IServerRoSessionData) this.sessionDataFactory.getAppSessionData(ServerRoSession.class, sessionId); sessionData.setApplicationId(applicationId); ServerRoSessionImpl serverSession = new ServerRoSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); iss.addSession(serverSession); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRoSession.class + "," + ServerRoSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Ro Session.", e); } return appSession; } @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { AppSession appSession = null; if (sessionId == null) { throw new IllegalArgumentException("Session-Id must not be null"); } if(!this.iss.exists(sessionId)) { return null; } try { if (aClass == ClientRoSession.class) { IClientRoSessionData sessionData = (IClientRoSessionData) this.sessionDataFactory.getAppSessionData(ClientRoSession.class, sessionId); ClientRoSessionImpl clientSession = new ClientRoSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientSessionListener(), this.getClientContextListener(), this.getStateListener()); // this goes first! clientSession.getSessions().get(0).setRequestListener(clientSession); appSession = clientSession; } else if (aClass == ServerRoSession.class) { IServerRoSessionData sessionData = (IServerRoSessionData) this.sessionDataFactory.getAppSessionData(ServerRoSession.class, sessionId); ServerRoSessionImpl serverSession = new ServerRoSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getServerSessionListener(), this.getServerContextListener(), this.getStateListener()); serverSession.getSessions().get(0).setRequestListener(serverSession); appSession = serverSession; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRoSession.class + "," + ServerRoSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Credit-Control Session.", e); } return appSession; } // Message Handlers --------------------------------------------------------- public void doCreditControlRequest(ServerRoSession session, RoCreditControlRequest request) throws InternalException { } public void doCreditControlAnswer(ClientRoSession session, RoCreditControlRequest request, RoCreditControlAnswer answer) throws InternalException { } public void doReAuthRequest(ClientRoSession session, ReAuthRequest request) throws InternalException { } public void doReAuthAnswer(ServerRoSession session, ReAuthRequest request, ReAuthAnswer answer) throws InternalException { } public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException { } // Message Factory Methods -------------------------------------------------- public RoCreditControlAnswer createCreditControlAnswer(Answer answer) { return new RoCreditControlAnswerImpl(answer); } public RoCreditControlRequest createCreditControlRequest(Request req) { return new RoCreditControlRequestImpl(req); } public ReAuthAnswer createReAuthAnswer(Answer answer) { return new ReAuthAnswerImpl(answer); } public ReAuthRequest createReAuthRequest(Request req) { return new ReAuthRequestImpl(req); } // Context Methods ---------------------------------------------------------- @SuppressWarnings("unchecked") public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter Ro SessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum) */ @SuppressWarnings("unchecked") public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Ro SessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[]{source, oldState, newState}); } // FIXME: add ctx methods proxy calls! public void sessionSupervisionTimerExpired(ServerRoSession session) { // this.resourceAdaptor.sessionDestroyed(session.getSessions().get(0).getSessionId(), session); session.release(); } @SuppressWarnings("unchecked") public void sessionSupervisionTimerReStarted(ServerRoSession session, ScheduledFuture future) { // TODO Complete this method. } @SuppressWarnings("unchecked") public void sessionSupervisionTimerStarted(ServerRoSession session, ScheduledFuture future) { // TODO Complete this method. } @SuppressWarnings("unchecked") public void sessionSupervisionTimerStopped(ServerRoSession session, ScheduledFuture future) { // TODO Complete this method. } public void timeoutExpired(Request request) { // FIXME What should we do when there's a timeout? } public void denyAccessOnDeliverFailure(ClientRoSession clientRoSessionImpl, Message request) { // TODO Complete this method. } public void denyAccessOnFailureMessage(ClientRoSession clientRoSessionImpl) { // TODO Complete this method. } public void denyAccessOnTxExpire(ClientRoSession clientRoSessionImpl) { // this.resourceAdaptor.sessionDestroyed(clientRoSessionImpl.getSessions().get(0).getSessionId(), // clientRoSessionImpl); clientRoSessionImpl.release(); } public int getDefaultCCFHValue() { return defaultCreditControlFailureHandling; } public int getDefaultDDFHValue() { return defaultDirectDebitingFailureHandling; } public long getDefaultTxTimerValue() { return defaultTxTimerValue; } public void grantAccessOnDeliverFailure(ClientRoSession clientRoSessionImpl, Message request) { // TODO Auto-generated method stub } public void grantAccessOnFailureMessage(ClientRoSession clientRoSessionImpl) { // TODO Auto-generated method stub } public void grantAccessOnTxExpire(ClientRoSession clientRoSessionImpl) { // TODO Auto-generated method stub } public void indicateServiceError(ClientRoSession clientRoSessionImpl) { // TODO Auto-generated method stub } public void txTimerExpired(ClientRoSession session) { // this.resourceAdaptor.sessionDestroyed(session.getSessions().get(0).getSessionId(), session); session.release(); } public long[] getApplicationIds() { // FIXME: What should we do here? return new long[] { 4 }; } public long getDefaultValidityTime() { return this.defaultValidityTime; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.ro; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.ro.ClientRoSession; import org.jdiameter.api.ro.ServerRoSession; import org.jdiameter.client.impl.app.ro.ClientRoSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.ro.IRoSessionData; import org.jdiameter.server.impl.app.ro.ServerRoSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class RoLocalSessionDataFactory implements IAppSessionDataFactory<IRoSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IRoSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientRoSession.class)) { ClientRoSessionDataLocalImpl data = new ClientRoSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerRoSession.class)) { ServerRoSessionDataLocalImpl data = new ServerRoSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.ro; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.app.StateMachine; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.ro.IRoSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public abstract class AppRoSessionImpl extends AppSessionImpl implements NetworkReqListener, StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); //FIXME: those must be recreated from local resources! //FIXME: change this to single ref! protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); public AppRoSessionImpl(ISessionFactory sf, IRoSessionData sessionData) { super(sf,sessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } public void release() { //stateListeners.clear(); super.release(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.rf; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rf.ClientRfSession; import org.jdiameter.api.rf.ServerRfSession; import org.jdiameter.client.impl.app.rf.ClientRfSessionDataLocalImpl; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.rf.IRfSessionData; import org.jdiameter.server.impl.app.rf.ServerRfSessionDataLocalImpl; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class RfLocalSessionDataFactory implements IAppSessionDataFactory<IRfSessionData>{ /* (non-Javadoc) * @see org.jdiameter.common.api.app.IAppSessionDataFactory#getAppSessionData(java.lang.Class, java.lang.String) */ @Override public IRfSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) { if(clazz.equals(ClientRfSession.class)) { ClientRfSessionDataLocalImpl data = new ClientRfSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } else if(clazz.equals(ServerRfSession.class)) { ServerRfSessionDataLocalImpl data = new ServerRfSessionDataLocalImpl(); data.setSessionId(sessionId); return data; } throw new IllegalArgumentException(clazz.toString()); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.rf; import java.util.concurrent.ScheduledFuture; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.IllegalDiameterStateException; import org.jdiameter.api.InternalException; import org.jdiameter.api.OverloadException; import org.jdiameter.api.Request; import org.jdiameter.api.RouteException; import org.jdiameter.api.SessionFactory; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.rf.ClientRfSession; import org.jdiameter.api.rf.ClientRfSessionListener; import org.jdiameter.api.rf.ServerRfSession; import org.jdiameter.api.rf.ServerRfSessionListener; import org.jdiameter.api.rf.events.RfAccountingAnswer; import org.jdiameter.api.rf.events.RfAccountingRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.client.impl.app.rf.ClientRfSessionImpl; import org.jdiameter.client.impl.app.rf.IClientRfSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; import org.jdiameter.common.api.app.rf.IClientRfActionContext; import org.jdiameter.common.api.app.rf.IRfSessionData; import org.jdiameter.common.api.app.rf.IRfSessionFactory; import org.jdiameter.common.api.app.rf.IServerRfActionContext; import org.jdiameter.common.api.data.ISessionDatasource; import org.jdiameter.server.impl.app.rf.IServerRfSessionData; import org.jdiameter.server.impl.app.rf.ServerRfSessionImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Default Diameter Rf Session Factory implementation * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public class RfSessionFactoryImpl implements IRfSessionFactory, ServerRfSessionListener, ClientRfSessionListener, IClientRfActionContext, IServerRfActionContext, StateChangeListener<AppSession> { protected Logger logger = LoggerFactory.getLogger(RfSessionFactoryImpl.class); protected ServerRfSessionListener serverSessionListener; protected StateChangeListener<AppSession> stateListener; protected ClientRfSessionListener clientSessionListener; protected IClientRfActionContext clientContextListener; protected IServerRfActionContext serverContextListener; protected ISessionDatasource iss; protected ISessionFactory sessionFactory = null; protected long messageTimeout = 5000; protected ApplicationId applicationId; protected IAppSessionDataFactory<IRfSessionData> sessionDataFactory; protected RfSessionFactoryImpl() { } public RfSessionFactoryImpl(SessionFactory sessionFactory) { super(); this.sessionFactory = (ISessionFactory) sessionFactory; this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); this.sessionDataFactory = (IAppSessionDataFactory<IRfSessionData>) this.iss.getDataFactory(IRfSessionData.class); } // ACC Factory Methods // ------------------------------------------------------ /** * @return the serverSessionListener */ public ServerRfSessionListener getServerSessionListener() { if (this.serverSessionListener != null) { return serverSessionListener; } else { return this; } } /** * @param serverSessionListener * the serverSessionListener to set */ public void setServerSessionListener(ServerRfSessionListener serverSessionListener) { this.serverSessionListener = serverSessionListener; } /** * @return the stateListener */ public StateChangeListener<AppSession> getStateListener() { if (this.stateListener != null) { return stateListener; } else { return this; } } /** * @param stateListener * the stateListener to set */ public void setStateListener(StateChangeListener<AppSession> stateListener) { this.stateListener = stateListener; } /** * @return the clientSessionListener */ public ClientRfSessionListener getClientSessionListener() { if (this.clientSessionListener != null) { return clientSessionListener; } else { return this; } } /** * @param clientSessionListener * the clientSessionListener to set */ public void setClientSessionListener(ClientRfSessionListener clientSessionListener) { this.clientSessionListener = clientSessionListener; } /** * @return the clientContextListener */ public IClientRfActionContext getClientContextListener() { if (this.clientContextListener != null) { return clientContextListener; } else { return this; } } /** * @param clientContextListener * the clientContextListener to set */ public void setClientContextListener(IClientRfActionContext clientContextListener) { this.clientContextListener = clientContextListener; } /** * @return the serverContextListener */ public IServerRfActionContext getServerContextListener() { if (this.serverContextListener != null) { return serverContextListener; } else { return this; } } /** * @param serverContextListener * the serverContextListener to set */ public void setServerContextListener(IServerRfActionContext serverContextListener) { this.serverContextListener = serverContextListener; } /** * @return the messageTimeout */ public long getMessageTimeout() { return messageTimeout; } /** * @param messageTimeout * the messageTimeout to set */ public void setMessageTimeout(long messageTimeout) { this.messageTimeout = messageTimeout; } /** * @return the sessionFactory */ public ISessionFactory getSessionFactory() { return sessionFactory; } /** * @param sessionFactory * the sessionFactory to set */ public void setSessionFactory(ISessionFactory sessionFactory) { this.sessionFactory = sessionFactory; if (this.iss == null) { this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class); } } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.acc.IAccSessionFactory#getApplicationId() */ public ApplicationId getApplicationId() { return this.applicationId; } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.acc.IAccSessionFactory#setApplicationId( * org.jdiameter.api.ApplicationId) */ public void setApplicationId(ApplicationId id) { this.applicationId = id; } // App Session Factory // ------------------------------------------------------ @Override public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) { if (sessionId == null) { throw new IllegalArgumentException("SessionId must not be null"); } if (!this.iss.exists(sessionId)) { return null; } AppSession appSession = null; try { if (aClass == ServerRfSession.class) { IServerRfSessionData sessionData = (IServerRfSessionData) this.sessionDataFactory.getAppSessionData(ServerRfSession.class, sessionId); // FIXME: determine how to get boolean flag! ServerRfSessionImpl session = new ServerRfSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getServerContextListener(), getStateListener(), messageTimeout, true); session.getSessions().get(0).setRequestListener(session); appSession = session; } else if (aClass == ClientRfSession.class) { IClientRfSessionData sessionData = (IClientRfSessionData) this.sessionDataFactory.getAppSessionData(ClientRfSession.class, sessionId); ClientRfSessionImpl session = new ClientRfSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getClientContextListener(), getStateListener(), this.getApplicationId()); session.getSessions().get(0).setRequestListener(session); appSession = session; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRfSession.class + "," + ServerRfSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Rf Session.", e); } return appSession; } public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) { try { if (aClass == ServerRfSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IServerRfSessionData sessionData = (IServerRfSessionData) this.sessionDataFactory.getAppSessionData(ServerRfSession.class, sessionId); sessionData.setApplicationId(applicationId); // FIXME: determine how to get boolean flag! ServerRfSessionImpl session = new ServerRfSessionImpl(sessionData, sessionFactory, getServerSessionListener(), getServerContextListener(), getStateListener(), messageTimeout, true); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } else if (aClass == ClientRfSession.class) { if (sessionId == null) { if (args != null && args.length > 0 && args[0] instanceof Request) { Request request = (Request) args[0]; sessionId = request.getSessionId(); } else { sessionId = this.sessionFactory.getSessionId(); } } IClientRfSessionData sessionData = (IClientRfSessionData) this.sessionDataFactory.getAppSessionData(ClientRfSession.class, sessionId); sessionData.setApplicationId(applicationId); ClientRfSessionImpl session = new ClientRfSessionImpl(sessionData, sessionFactory, getClientSessionListener(), getClientContextListener(), getStateListener(), this.getApplicationId()); iss.addSession(session); session.getSessions().get(0).setRequestListener(session); return session; } else { throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ClientRfSession.class + "," + ServerRfSession.class + "]"); } } catch (Exception e) { logger.error("Failure to obtain new Rf Session.", e); } return null; } // State Change Listener // ---------------------------------------------------- @SuppressWarnings("unchecked") public void stateChanged(Enum oldState, Enum newState) { logger.info("Diameter ACC SessionFactory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState); } /* * (non-Javadoc) * * @see * org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, * java.lang.Enum, java.lang.Enum) */ @SuppressWarnings("unchecked") public void stateChanged(AppSession source, Enum oldState, Enum newState) { logger.info("Diameter Rf SessionFactory :: stateChanged :: source[{}], oldState[{}], newState[{}]", new Object[] { source, oldState, newState }); } // /////////////////// // Event listeners // // /////////////////// public void doRfAccountingRequestEvent(ServerRfSession appSession, RfAccountingRequest acr) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base RfSessionFactory :: doAccRequestEvent :: appSession[" + appSession + "], Request[" + acr + "]"); } public void doRfAccountingAnswerEvent(ClientRfSession appSession, RfAccountingRequest acr, RfAccountingAnswer aca) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("doRfAnswerEvent :: appSession[" + appSession + "], Request[" + acr + "], Answer[" + aca + "]"); } public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException { logger.info("Diameter Base RfountingSessionFactory :: doOtherEvent :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]"); } // Client context // ----------------------------------------------------------- /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.Rf.IClientRfActionContext#disconnectUserOrDev * (org.jdiameter.api.Request) */ public void disconnectUserOrDev(ClientRfSession appSession, Request sessionTermRequest) throws InternalException { logger.info("disconnectUserOrDev :: appSession[" + appSession + "], Request[" + sessionTermRequest + "]"); } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.Rf.IClientRfActionContext#failedSendRecord * (org.jdiameter.api.Request) */ public boolean failedSendRecord(ClientRfSession appSession, Request rfRequest) throws InternalException { logger.info("failedSendRecord :: appSession[" + appSession + "], Request[" + rfRequest + "]"); return false; } /* * (non-Javadoc) * * @see org.jdiameter.common.api.app.acc.IClientAccActionContext# * interimIntervalElapses(org.jdiameter.api.Request) */ public void interimIntervalElapses(ClientRfSession appSession, Request interimRequest) throws InternalException { logger.info("interimIntervalElapses :: appSession[" + appSession + "], Request[" + interimRequest + "]"); } // Server context // ----------------------------------------------------------- /* * (non-Javadoc) * * @seeorg.jdiameter.common.api.app.Rf.IServerRfActionContext# * sessionTimeoutElapses(org.jdiameter.api.Rf.ServerRfSession) */ public void sessionTimeoutElapses(ServerRfSession appSession) throws InternalException { logger.info("sessionTimeoutElapses :: appSession[" + appSession + "]"); } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.Rf.IServerRfActionContext#sessionTimerStarted * (org.jdiameter.api.Rf.ServerRfSession, * java.util.concurrent.ScheduledFuture) */ @SuppressWarnings("unchecked") public void sessionTimerStarted(ServerRfSession appSession, ScheduledFuture timer) throws InternalException { logger.info("sessionTimerStarted :: appSession[" + appSession + "]"); } /* * (non-Javadoc) * * @see * org.jdiameter.common.api.app.Rf.IServerRfActionContext#srssionTimerCanceled * (org.jdiameter.api.Rf.ServerRfSession, * java.util.concurrent.ScheduledFuture) */ @SuppressWarnings("unchecked") public void sessionTimerCanceled(ServerRfSession appSession, ScheduledFuture timer) throws InternalException { logger.info("sessionTimerCanceled :: appSession[" + appSession + "]"); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.rf; import static org.jdiameter.api.Avp.ACC_RECORD_NUMBER; import org.jdiameter.api.Answer; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.rf.events.RfAccountingAnswer; import org.jdiameter.common.impl.app.AppAnswerEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RfAccountingAnswerImpl extends AppAnswerEventImpl implements RfAccountingAnswer { private static final long serialVersionUID = 1L; /** * @param request * @param vendorId * @param resultCode */ public RfAccountingAnswerImpl(Request request, long vendorId, long resultCode) { super(request, vendorId, resultCode); } /** * @param request * @param resultCode */ public RfAccountingAnswerImpl(Request request, long resultCode) { super(request, resultCode); } /** * @param request */ public RfAccountingAnswerImpl(Request request) { super(request); } public RfAccountingAnswerImpl(Request request, int accountRecordType, int accReqNumber, long resultCode) { super(request.createAnswer(resultCode)); try { getMessage().getAvps().addAvp(Avp.ACC_RECORD_TYPE, accountRecordType); getMessage().getAvps().addAvp(Avp.ACC_RECORD_NUMBER, accReqNumber); } catch (Exception e) { throw new IllegalArgumentException(e); } } public RfAccountingAnswerImpl(Answer answer) { super(answer); } public int getAccountingRecordType() throws AvpDataException { Avp accRecordTypeAvp = message.getAvps().getAvp(Avp.ACC_RECORD_TYPE); if (accRecordTypeAvp != null) { return accRecordTypeAvp.getInteger32(); } else { throw new AvpDataException("Avp ACC_RECORD_TYPE not found"); } } public long getAccountingRecordNumber() throws AvpDataException { Avp accRecordNumberAvp = message.getAvps().getAvp(ACC_RECORD_NUMBER); if (accRecordNumberAvp != null) { return accRecordNumberAvp.getUnsigned32(); } else { throw new AvpDataException("Avp ACC_RECORD_NUMBER not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.rf; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.Answer; import org.jdiameter.api.ApplicationId; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.api.Request; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.rf.events.RfAccountingAnswer; import org.jdiameter.api.rf.events.RfAccountingRequest; import org.jdiameter.client.api.ISessionFactory; import org.jdiameter.common.api.app.rf.IRfSessionData; import org.jdiameter.common.impl.app.AppSessionImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public abstract class AppRfSessionImpl extends AppSessionImpl implements NetworkReqListener, org.jdiameter.api.app.StateMachine { protected Lock sendAndStateLock = new ReentrantLock(); protected ApplicationId appId; protected transient List<StateChangeListener> stateListeners = new CopyOnWriteArrayList<StateChangeListener>(); public AppRfSessionImpl(ISessionFactory sf, IRfSessionData sessionData) { super(sf, sessionData); } public void addStateChangeNotification(StateChangeListener listener) { if (!stateListeners.contains(listener)) { stateListeners.add(listener); } } public void removeStateChangeNotification(StateChangeListener listener) { stateListeners.remove(listener); } protected RfAccountingRequest createAccountRequest(Request request) { return new RfAccountingRequestImpl(request); } protected RfAccountingAnswer createAccountAnswer(Answer answer) { return new RfAccountingAnswerImpl(answer); } public void release() { //stateListeners.clear(); super.release(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.impl.app.rf; import static org.jdiameter.api.Avp.ACC_RECORD_NUMBER; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.rf.events.RfAccountingRequest; import org.jdiameter.common.impl.app.AppRequestEventImpl; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class RfAccountingRequestImpl extends AppRequestEventImpl implements RfAccountingRequest { private static final long serialVersionUID = 1L; public RfAccountingRequestImpl(AppSession session, int accountRecordType, int accReqNumber, String destRealm, String destHost) { super(session.getSessions().get(0).createRequest(code, session.getSessionAppId(), destRealm, destHost)); try { getMessage().getAvps().addAvp(Avp.ACC_RECORD_TYPE, accountRecordType); getMessage().getAvps().addAvp(Avp.ACC_RECORD_NUMBER, accReqNumber); } catch (Exception e) { throw new IllegalArgumentException(e); } } public RfAccountingRequestImpl(Request request) { super(request); } public int getAccountingRecordType() throws AvpDataException { Avp accRecordTypeAvp = message.getAvps().getAvp(Avp.ACC_RECORD_TYPE); if (accRecordTypeAvp != null) { return accRecordTypeAvp.getInteger32(); } else { throw new AvpDataException("Avp ACC_RECORD_TYPE not found"); } } public long getAccountingRecordNumber() throws AvpDataException { Avp accRecordNumberAvp = message.getAvps().getAvp(ACC_RECORD_NUMBER); if (accRecordNumberAvp != null) { return accRecordNumberAvp.getUnsigned32(); } else { throw new AvpDataException("Avp ACC_RECORD_NUMBER not found"); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class BaseThreadFactory implements ThreadFactory { public static final String ENTITY_NAME = "ThreadGroup"; private ThreadGroup threadGroup; private String threadPoolName; private AtomicInteger count = new AtomicInteger(0); public BaseThreadFactory(String threadPoolName) { this.threadPoolName = threadPoolName; this.threadGroup = new ThreadGroup("jd " + threadPoolName + " group"); } public Thread newThread(Runnable runnable) { return new Thread(threadGroup, runnable, threadPoolName + "-" + count.getAndIncrement()); } public Thread newThread(String namePrefix, Runnable runnable) { return new Thread(threadGroup, runnable, namePrefix + "-" + count.getAndIncrement()); } public ThreadGroup getThreadGroup() { return threadGroup; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.common.api.statistic.IStatistic; import static org.jdiameter.common.api.statistic.IStatisticRecord.Counters.BrokenTasks; import static org.jdiameter.common.api.statistic.IStatisticRecord.Counters.WorkingThread; import org.jdiameter.common.api.statistic.IStatisticRecord; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class DefaultRunnable extends AbstractTask<Runnable> implements Runnable { public DefaultRunnable(Runnable task, IStatistic statistic, IStatisticRecord... statisticRecords) { super(task, statistic, statisticRecords); } public void run() { if (getCounter(WorkingThread) != null) { getCounter(WorkingThread).inc(); } long time = System.nanoTime(); try { parentTask.run(); } catch (RuntimeException e) { if (getCounter(BrokenTasks) != null) { getCounter(BrokenTasks).inc(); } throw e; } finally { updateTimeStatistic(time, time - createdTime); if (getCounter(WorkingThread) != null) { getCounter(WorkingThread).dec(); } } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.common.api.statistic.IStatistic; import static org.jdiameter.common.api.statistic.IStatisticRecord.Counters.*; import org.jdiameter.common.api.statistic.IStatisticRecord; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class DefaultCallable<L> extends AbstractTask<Callable<L>> implements Callable<L> { public DefaultCallable(Callable<L> task, IStatistic statistic, IStatisticRecord... statisticRecords) { super(task, statistic, statisticRecords); } public L call() throws Exception { long time = 0; if(statistic.isEnabled()) { getCounter(WorkingThread).inc(); time = System.nanoTime(); } try { return parentTask.call(); } catch (CancellationException e) { if(statistic.isEnabled()) getCounter(CanceledTasks).inc(); throw e; } catch (Exception e) { if(statistic.isEnabled()) getCounter(BrokenTasks).inc(); throw e; } finally { if(statistic.isEnabled()) { updateTimeStatistic(time, time - createdTime); getCounter(WorkingThread).dec(); } } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.api.Configuration; import org.jdiameter.client.impl.helpers.Parameters; import org.jdiameter.common.api.concurrent.IConcurrentEntityFactory; import org.jdiameter.common.api.statistic.IStatistic; import static org.jdiameter.common.api.statistic.IStatisticRecord.Counters.*; import static org.jdiameter.common.api.statistic.IStatistic.Groups.ScheduledExecService; import org.jdiameter.common.api.statistic.IStatisticManager; import org.jdiameter.common.api.statistic.IStatisticRecord; import java.util.List; import java.util.concurrent.*; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class CommonScheduledExecutorService extends ScheduledThreadPoolExecutor { private IStatistic statistic; private IConcurrentEntityFactory entityFactory; private IStatisticRecord execTimeSumm; private IStatisticRecord execTimeCount; private IStatisticRecord waitTimeSumm; private IStatisticRecord waitTimeCount; private IStatisticManager statisticFactory; public CommonScheduledExecutorService(String name, Configuration config, final IConcurrentEntityFactory entityFactory, IStatisticManager statisticFactory) { super(config == null ? (Integer) Parameters.ConcurrentEntityPoolSize.defValue() : config.getIntValue(Parameters.ConcurrentEntityPoolSize.ordinal(), (Integer) Parameters.ConcurrentEntityPoolSize.defValue())); this.statisticFactory = statisticFactory; this.entityFactory = entityFactory; final IStatisticRecord rejectedCount = statisticFactory.newCounterRecord(RejectedTasks); execTimeSumm = statisticFactory.newCounterRecord("TimeSumm", "TimeSumm"); execTimeCount = statisticFactory.newCounterRecord("TimeCount", "TimeCount"); waitTimeSumm = statisticFactory.newCounterRecord("TimeSumm", "TimeSumm"); waitTimeCount = statisticFactory.newCounterRecord("TimeCount", "TimeCount"); //XXX: YYY: no need to remove? it lives as long stack does. statistic = statisticFactory.newStatistic(name,ScheduledExecService, rejectedCount); final IStatisticRecord execTimeCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.ExecTimeTask, new AbstractTask.AverageValueHolder( statistic, IStatisticRecord.Counters.ExecTimeTask), execTimeSumm, execTimeCount); final IStatisticRecord waitTimeCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.WaitTimeTask, new AbstractTask.AverageValueHolder( statistic, IStatisticRecord.Counters.WaitTimeTask), waitTimeSumm, waitTimeCount); statistic.appendCounter(statisticFactory.newCounterRecord(WorkingThread), statisticFactory.newCounterRecord(CanceledTasks), statisticFactory.newCounterRecord(BrokenTasks), execTimeCounter, waitTimeCounter, statisticFactory.newCounterRecord(WaitTimeTask)); if (config == null) { this.setThreadFactory(entityFactory.newThreadFactory(name)); } else { this.setThreadFactory(entityFactory.newThreadFactory(config.getStringValue(Parameters.ConcurrentEntityDescription.ordinal(), name))); } super.setRejectedExecutionHandler(entityFactory.newRejectedExecutionHandler(rejectedCount)); } @Override public ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) { return super.schedule(this.entityFactory.newDefaultRunnable(runnable, statistic,execTimeSumm, execTimeCount, waitTimeSumm, waitTimeCount), delay, unit); } @Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { return super.schedule(this.entityFactory.newDefaultCallable(callable, statistic,execTimeSumm, execTimeCount, waitTimeSumm, waitTimeCount), delay, unit); } @Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable runnable, long initialDelay, long period, TimeUnit unit) { return super.scheduleAtFixedRate(this.entityFactory.newDefaultRunnable(runnable, statistic, execTimeSumm, execTimeCount, waitTimeSumm, waitTimeCount), initialDelay, period, unit); } public IStatistic getStatistic() { return statistic; } public void shutdown() { this.statisticFactory.removeStatistic(statistic); super.shutdown(); } public List<Runnable> shutdownNow() { this.statisticFactory.removeStatistic(statistic); return super.shutdownNow(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.api.Configuration; import org.jdiameter.client.impl.helpers.Parameters; import org.jdiameter.common.api.concurrent.IConcurrentEntityFactory; import org.jdiameter.common.api.concurrent.IConcurrentFactory; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticManager; import org.jdiameter.common.api.statistic.IStatisticRecord; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class ConcurrentFactory implements IConcurrentFactory { private BaseThreadFactory threadFactory; private Map<String, CommonScheduledExecutorService> scheduledExecutorServices; private Configuration[] config; private IStatisticManager statisticFactory; private IStatistic statistic; private IConcurrentEntityFactory entityFactory; public ConcurrentFactory(Configuration config, IStatisticManager statisticFactory, IConcurrentEntityFactory entityFactory) { this.config = config.getChildren(Parameters.Concurrent.ordinal()); this.entityFactory = entityFactory; Configuration dgConfig = getConfigByName(BaseThreadFactory.ENTITY_NAME); String defThreadGroupName = dgConfig != null ? dgConfig.getStringValue(Parameters.ConcurrentEntityDescription.ordinal(), (String) Parameters.ConcurrentEntityDescription.defValue()) : (String) Parameters.ConcurrentEntityDescription.defValue(); threadFactory = (BaseThreadFactory) entityFactory.newThreadFactory(defThreadGroupName); scheduledExecutorServices = new ConcurrentHashMap<String, CommonScheduledExecutorService>(); IStatisticRecord threadCount = statisticFactory.newCounterRecord( IStatisticRecord.Counters.ConcurrentThread, new IStatisticRecord.IntegerValueHolder() { public String getValueAsString() { return getValueAsInt() + ""; } public int getValueAsInt() { return getThreadGroup().activeCount(); } }); //TODO: make use of this stat.... IStatisticRecord schedExeServiceCount = statisticFactory.newCounterRecord( IStatisticRecord.Counters.ConcurrentScheduledExecutedServices, new IStatisticRecord.IntegerValueHolder() { public String getValueAsString() { return getValueAsInt() + ""; } public int getValueAsInt() { return scheduledExecutorServices.size(); } }); statistic = statisticFactory.newStatistic("scheduled",IStatistic.Groups.Concurrent, threadCount, schedExeServiceCount); this.statisticFactory = statisticFactory; } /** * fetch configuration for executor * @param name * @return */ private Configuration getConfigByName(String name) { if (config != null) { for (Configuration c : config) { if (c != null && c.getStringValue(Parameters.ConcurrentEntityName.ordinal(), "").equals(name)) { return c; } } } return null; } public Thread getThread(Runnable runnable) { return threadFactory.newThread(runnable); } public Thread getThread(String namePrefix, Runnable runnuble) { return threadFactory.newThread(namePrefix, runnuble); } public List<Thread> getThreads() { Thread[] threads = new Thread[threadFactory.getThreadGroup().activeCount()]; threadFactory.getThreadGroup().enumerate(threads); return Arrays.asList(threads); } public ThreadGroup getThreadGroup() { return threadFactory.getThreadGroup(); } public ScheduledExecutorService getScheduledExecutorService(String name) { CommonScheduledExecutorService service = null; if(!scheduledExecutorServices.containsKey(name)) { service = new CommonScheduledExecutorService(name, getConfigByName(name), this.entityFactory, statisticFactory); scheduledExecutorServices.put(name,service); } else { service = scheduledExecutorServices.get(name); } return service; } public Collection<ScheduledExecutorService> getScheduledExecutorServices() { List<ScheduledExecutorService> external = new ArrayList<ScheduledExecutorService>(scheduledExecutorServices.values()); return external; } public void shutdownNow(ScheduledExecutorService service) { for (String name : scheduledExecutorServices.keySet()) { ExecutorService e = scheduledExecutorServices.get(name); if (e == service) { e.shutdownNow(); scheduledExecutorServices.remove(name); break; } } } public IStatistic getStatistic() { return statistic; } public List<IStatistic> getStatistics() { List<IStatistic> statistics = new ArrayList<IStatistic>(); for (CommonScheduledExecutorService e : scheduledExecutorServices.values()) { statistics.add(e.getStatistic()); } return statistics; } public void shutdownAllNow() { for (String name : scheduledExecutorServices.keySet()) { ExecutorService e = scheduledExecutorServices.remove(name); e.shutdownNow(); } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import java.util.concurrent.Callable; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadFactory; import org.jdiameter.common.api.concurrent.IConcurrentEntityFactory; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticRecord; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class ConcurrentEntityFactory implements IConcurrentEntityFactory { // TODO: get rid of that? public ConcurrentEntityFactory() { } public ThreadFactory newThreadFactory(String threadPoolName) { return new BaseThreadFactory(threadPoolName); } public RejectedExecutionHandler newRejectedExecutionHandler(IStatisticRecord rejectedCount) { return new DefaultRejectedExecutionHandler(rejectedCount); } public <L> Callable<L> newDefaultCallable(Callable<L> runnable, IStatistic statistic, IStatisticRecord... statisticRecords) { return new DefaultCallable<L>(runnable, statistic, statisticRecords); } public Runnable newDefaultRunnable(Runnable runnable, IStatistic statistic, IStatisticRecord... statisticRecords) { return new DefaultRunnable(runnable, statistic, statisticRecords); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.common.api.statistic.IStatisticRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class DefaultRejectedExecutionHandler implements RejectedExecutionHandler { private static final Logger log = LoggerFactory.getLogger(DefaultRejectedExecutionHandler.class); private IStatisticRecord rejectedCount; /** * @param rejectedCount */ public DefaultRejectedExecutionHandler(IStatisticRecord rejectedCount) { this.rejectedCount = rejectedCount; } public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { log.debug("Task rejected {}", r); if(rejectedCount.isEnabled()) rejectedCount.inc(); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.concurrent; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticRecord; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ abstract class AbstractTask<L> { protected L parentTask; protected long createdTime = System.nanoTime(); protected IStatistic statistic; protected IStatisticRecord execTimeSumm; protected IStatisticRecord execTimeCount; protected IStatisticRecord waitTimeSumm; protected IStatisticRecord waitTimeCount; public AbstractTask(L task, final IStatistic statistic, IStatisticRecord... statisticRecords) { this.parentTask = task; execTimeSumm = statisticRecords[0]; execTimeCount = statisticRecords[1]; waitTimeSumm = statisticRecords[2]; waitTimeCount = statisticRecords[3]; this.statistic = statistic; } protected IStatisticRecord getCounter(IStatisticRecord.Counters counter) { return statistic.getRecordByName(counter.name()); } protected void updateTimeStatistic(long time, long waitTime) { if(statistic.isEnabled()) { execTimeSumm.inc((System.nanoTime() - time) / 999999); execTimeCount.inc(); waitTimeSumm.inc(waitTime / 999999); waitTimeCount.inc(); } } @Override public boolean equals(Object o) { return this == o || parentTask.equals(o); } @Override public int hashCode() { return parentTask.hashCode(); } public static class AverageValueHolder implements IStatisticRecord.ValueHolder { private IStatistic statistic; private IStatisticRecord.Counters counter; public AverageValueHolder(IStatistic statistic, IStatisticRecord.Counters counter) { this.statistic = statistic; this.counter = counter; } public double getValueAsDouble() { IStatisticRecord record = statistic.getRecordByName(counter.name()); if (statistic.isEnabled() && (record.getChilds().length == 2 || record.getChilds()[1].getValueAsLong() != 0) ) { long count = record.getChilds()[1].getValueAsLong(); return ((float) record.getChilds()[0].getValueAsLong()) / ((float) (count != 0 ? count : 1)); } else { return 0; } } public String getValueAsString() { return String.valueOf(getValueAsDouble()); } } }
Java
/* * TeleStax, Open Source Cloud Communications * Copyright 2011-2014, TeleStax Inc. and individual contributors * by the @authors tag. * * This program is free software: you can redistribute it and/or modify * under the terms of the GNU Affero General Public License as * published by the Free Software Foundation; either version 3 of * the License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> * * This file incorporates work covered by the following copyright and * permission notice: * * JBoss, Home of Professional Open Source * Copyright 2007-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.jdiameter.common.impl.controller; import java.util.ArrayList; import java.util.List; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jdiameter.api.IllegalDiameterStateException; import org.jdiameter.api.InternalException; import org.jdiameter.api.Peer; import org.jdiameter.api.URI; import org.jdiameter.client.impl.helpers.UIDGenerator; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticManager; import org.jdiameter.common.api.statistic.IStatisticRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class AbstractPeer implements Comparable<Peer> { private static final Logger logger = LoggerFactory.getLogger(AbstractPeer.class); public static final int INT_COMMON_APP_ID = 0xffffffff; protected static UIDGenerator uid = new UIDGenerator(); // Statistic protected IStatistic statistic; protected List<IStatisticRecord> perSecondRecords = new ArrayList<IStatisticRecord>(); protected URI uri; protected IStatisticManager statisticFactory; //Added locks to make statistics creation and removal thread safe private Lock statisticsLock = new ReentrantLock(); public AbstractPeer(URI uri, IStatisticManager statisticFactory) { this.uri = uri; this.statisticFactory = statisticFactory; } protected void createPeerStatistics() { logger.debug("Creating Peer Statistics for URI {}", this.uri); // PCB - Added locking around this so that the stats cannot be attempted // to be initialized twice by 2 threads entering this function at the same time try { statisticsLock.lock(); if (this.statistic != null) { return; } String uriString = uri == null ? "local" : uri.toString(); IStatisticRecord appGenRequestCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.AppGenRequest); IStatisticRecord appGenCPSRequestCounter = statisticFactory.newPerSecondCounterRecord(uriString,IStatisticRecord.Counters.AppGenRequestPerSecond, appGenRequestCounter); IStatisticRecord appGenRejectedRequestCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.AppGenRejectedRequest); perSecondRecords.add(appGenCPSRequestCounter); IStatisticRecord appGenResponseCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.AppGenResponse); IStatisticRecord appGenCPSResponseCounter = statisticFactory.newPerSecondCounterRecord(uriString,IStatisticRecord.Counters.AppGenResponsePerSecond, appGenResponseCounter); IStatisticRecord appGenRejectedResponseCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.AppGenRejectedResponse); perSecondRecords.add(appGenCPSResponseCounter); IStatisticRecord netGenRequestCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.NetGenRequest); IStatisticRecord netGenCPSRequestCounter = statisticFactory.newPerSecondCounterRecord(uriString,IStatisticRecord.Counters.NetGenRequestPerSecond, netGenRequestCounter); IStatisticRecord netGenRejectedRequestCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.NetGenRejectedRequest); perSecondRecords.add(netGenCPSRequestCounter); IStatisticRecord netGenResponseCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.NetGenResponse); IStatisticRecord netGenCPSResponseCounter = statisticFactory.newPerSecondCounterRecord(uriString,IStatisticRecord.Counters.NetGenResponsePerSecond, netGenResponseCounter); IStatisticRecord netGenRejectedResponseCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.NetGenRejectedResponse); perSecondRecords.add(netGenCPSResponseCounter); IStatisticRecord sysGenResponseCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.SysGenResponse); this.statistic = statisticFactory.newStatistic(uriString,IStatistic.Groups.Peer, appGenRequestCounter, appGenCPSRequestCounter, appGenRejectedRequestCounter, appGenResponseCounter, appGenCPSResponseCounter, appGenRejectedResponseCounter, netGenRequestCounter, netGenCPSRequestCounter, netGenRejectedRequestCounter, netGenResponseCounter, netGenCPSResponseCounter, netGenRejectedResponseCounter, sysGenResponseCounter ); } finally { logger.debug("Completed creating Peer Statistics for URI {}: {}", this.uri, this.statistic); if (this.statistic == null) { logger.warn("Failed to create Peer Statistics for URI {}, creating dummy and setting to disabled", this.uri); this.statistic = statisticFactory.newStatistic("local", IStatistic.Groups.Peer); this.statistic.enable(false); } statisticsLock.unlock(); } } protected void removePeerStatistics() { logger.debug("Removing Peer Statistics for URI {}", this.uri); //RG edited this to make removal of peer stats thread safe try { statisticsLock.lock(); if (this.statistic == null) { return; } for (IStatisticRecord rec : this.perSecondRecords) { this.statisticFactory.removePerSecondCounterRecord(rec); } this.statisticFactory.removeStatistic(this.statistic); this.perSecondRecords.clear(); this.statistic = null; } finally { logger.debug("Completed removing Peer Statistics for URI {}: {}", this.uri, this.statistic); statisticsLock.unlock(); } } public int compareTo(Peer o) { return uri.compareTo(o.getUri()); } /** * @throws IllegalDiameterStateException * @throws InternalException * */ protected void disconnect(int disconnectCause) throws InternalException, IllegalDiameterStateException { } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.validation; import java.util.ArrayList; import java.util.List; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpDataException; import org.jdiameter.api.AvpSet; import org.jdiameter.api.validation.AvpNotAllowedException; import org.jdiameter.api.validation.AvpRepresentation; /** * Implementation of {@link AvpRepresentation} interface. * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @since 1.5.4.0-build404 */ public class AvpRepresentationImpl implements AvpRepresentation { protected String description; protected boolean mayEncrypt; protected boolean _protected; protected boolean _mandatory; protected String ruleMandatory; protected String ruleProtected; protected String ruleVendorBit; protected String type; // String, in case user defines his own type // Usually this will be -1, as only SessionId has fixed position private int positionIndex = _FIX_POSITION_INDEX; protected int code = -1; protected long vendor = 0; protected boolean allowed = true; protected String multiplicityIndicator = "0"; protected String name = "Some-AVP"; protected boolean grouped = false; protected List<AvpRepresentation> children = new ArrayList<AvpRepresentation>(); protected boolean weak = false; public AvpRepresentationImpl(AvpRepresentationImpl clone) { this(-1, clone.code, clone.getVendorId(), clone.getMultiplicityIndicator(), clone.getName()); this.allowed = clone.allowed; this.code = clone.code; this.grouped = clone.grouped; this.multiplicityIndicator = clone.multiplicityIndicator; this.name = clone.name; this.positionIndex = clone.positionIndex; this.vendor = clone.vendor; this.weak = clone.weak; this._mandatory = clone._mandatory; this._protected = clone._protected; this.description = clone.description; this.mayEncrypt = clone.mayEncrypt; this.ruleMandatory = clone.ruleMandatory; this.ruleProtected = clone.ruleProtected; this.ruleVendorBit = clone.ruleVendorBit; this.type = clone.type; if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public AvpRepresentationImpl() { super(); this.weak = true; } /** * Constructor used to represent weak children. - weak means its only * defined by name in some other AVP. After configuration parse procedure is * complete weak children are resolved. Weak children should not be stored * in Set or any other has structure, its due to nature of hashing, which is * done on vendor and code, which for weak children is always different than * fully defined AVP representation. <br> * This constructor should be generally used by extending classes, as well as * no argument constructor. * * @param name * @param vendor */ public AvpRepresentationImpl(String name, long vendor) { super(); this.name = name; this.vendor = vendor; this.weak = true; } /** * This constructor is used my validator to lookup correct representation. * Its hash and equals methods will match to fully populated avp * representation in any data structure * * @param code * @param vendor */ public AvpRepresentationImpl(int code, long vendor) { super(); this.code = code; this.vendor = vendor; if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public AvpRepresentationImpl(int positionIndex, int code, long vendor, String multiplicityIndicator, String name) { super(); this.positionIndex = positionIndex; this.code = code; this.vendor = vendor; this.multiplicityIndicator = multiplicityIndicator; this.name = name; if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public AvpRepresentationImpl(int code, long vendor, String name) { super(); this.positionIndex = -1; this.code = code; this.vendor = vendor; this.multiplicityIndicator = _MP_ZERO_OR_MORE; this.name = name; if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public AvpRepresentationImpl(String name, String description, int code, boolean mayEncrypt, String ruleMandatory, String ruleProtected, String ruleVendorBit, long vendorId, String type) { // zero and more, since its definition. this(-1, code, vendorId, _MP_ZERO_OR_MORE, name); this.description = description; this.mayEncrypt = mayEncrypt; this.ruleMandatory = ruleMandatory; this.ruleProtected = ruleProtected; this.ruleVendorBit = ruleVendorBit; if (this.ruleMandatory == null || this.ruleMandatory.equals("")) { this.ruleMandatory = _DEFAULT_MANDATORY; } if (this.ruleProtected == null || this.ruleProtected.equals("")) { this.ruleProtected = _DEFAULT_PROTECTED; } if (this.ruleVendorBit == null || this.ruleVendorBit.equals("")) { this.ruleVendorBit = _DEFAULT_VENDOR; } this.type = type; this._mandatory = this.ruleMandatory.equals("must"); this._protected = this.ruleProtected.equals("must"); if (type.equals(Type.Grouped.toString())) { this.setGrouped(true); } if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public boolean isPositionFixed() { return this.positionIndex == _FIX_POSITION_INDEX; } public void markFixPosition(int index) { this.positionIndex = index; } public boolean isCountValidForMultiplicity(AvpSet destination, int numberToAdd) { AvpSet innerSet = destination.getAvps(getCode(), getVendorId()); int count = numberToAdd; if (innerSet != null) { count += innerSet.size(); } return this.isCountValidForMultiplicity(count); } public boolean isCountValidForMultiplicity(int avpCount) { // This covers not_allowed if (!allowed) { if (avpCount == 0) { return true; } } else { if (this.multiplicityIndicator.equals(_MP_ZERO_OR_MORE)) { if (avpCount >= 0) { return true; } } else if (this.multiplicityIndicator.equals(_MP_ZERO_OR_ONE)) { if ((avpCount == 0) || (avpCount == 1)) { return true; } } else if (this.multiplicityIndicator.equals(_MP_ONE)) { if (avpCount == 1) { return true; } } else if (this.multiplicityIndicator.equals(_MP_ONE_AND_MORE)) { if (avpCount >= 1) { return true; } } } // if we did not return, we are screwed. return false; } public static int get_FIX_POSITION_INDEX() { return _FIX_POSITION_INDEX; } public int getPositionIndex() { return positionIndex; } public int getCode() { return code; } public long getVendorId() { return vendor; } public boolean isAllowed() { return allowed; } public boolean isAllowed(int avpCode, long vendorId) { if (this.isGrouped()) { // make better get ? for (AvpRepresentation rep : this.children) { if (rep.getCode() == avpCode && rep.getVendorId() == vendorId) { return rep.isAllowed(); } else { continue; } } return true; } else { return false; } } public boolean isAllowed(int avpCode) { return this.isAllowed(avpCode, 0L); } public String getMultiplicityIndicator() { return multiplicityIndicator; } public String getName() { return name; } public boolean isGrouped() { return grouped; } public void setGrouped(boolean grouped) { this.grouped = grouped; } public List<AvpRepresentation> getChildren() { return children; } public void setChildren(List<AvpRepresentation> children) { this.children = children; } public void setCode(int code) { this.code = code; } public void setVendorId(long vendor) { this.vendor = vendor; } public void setMultiplicityIndicator(String multiplicityIndicator) { this.multiplicityIndicator = multiplicityIndicator; if (this.multiplicityIndicator.equals(_MP_NOT_ALLOWED)) { this.allowed = false; } } public void setName(String name) { this.name = name; } public boolean isWeak() { return weak; } public void markWeak(boolean isWeak) { this.weak = isWeak; } public String getDescription() { return description; } public boolean isMayEncrypt() { return mayEncrypt; } public String getRuleMandatory() { return ruleMandatory; } public int getRuleMandatoryAsInt() { return Rule.valueOf(ruleMandatory).ordinal(); } public String getRuleProtected() { return ruleProtected; } public int getRuleProtectedAsInt() { return Rule.valueOf(ruleProtected).ordinal(); } public String getRuleVendorBit() { return ruleVendorBit; } public int getRuleVendorBitAsInt() { return Rule.valueOf(ruleVendorBit).ordinal(); } public String getType() { return type; } public boolean isProtected() { return _protected; } public boolean isMandatory() { return _mandatory; } public void validate(Avp avp) throws AvpNotAllowedException { if (isGrouped()) { try { AvpSet avpAsGrouped = avp.getGrouped(); validate(avpAsGrouped); } catch (AvpDataException e) { throw new AvpNotAllowedException("Failed to parse AVP to grouped!", e, code, vendor); } } else { // dont care } } public void validate(AvpSet avpSet) throws AvpNotAllowedException { //this is used in RAs, cause ... AvpSet is asexual AVP, no code, no vendor // let it rip for (AvpRepresentation childrenVAvp : getChildren()) { AvpSet childSset = avpSet.getAvps(childrenVAvp.getCode(), childrenVAvp.getVendorId()); int count = childSset.size(); if (!childrenVAvp.isCountValidForMultiplicity(count)) { throw new AvpNotAllowedException("AVP: " + childrenVAvp + " has wrong count ,in grouped parent avp - " + (count) + ", allowed: " + childrenVAvp.getMultiplicityIndicator(), getCode(), getVendorId()); } if (childrenVAvp.isGrouped()) { for (int index = 0; index < childSset.size(); index++) { Avp presumablyGrouped = childSset.getAvpByIndex(index); childrenVAvp.validate(presumablyGrouped); } } // else we are good ? } } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("name: ").append(this.getName()).append(", code: ").append(this.getCode()).append(", vendor: ").append(this.getVendorId()).append(", weak: ") .append(this.isWeak()).append(", grouped: ").append(this.isGrouped()).append(", type: ").append(this.getType()).append(", multiplicity: ") .append(this.getMultiplicityIndicator()); if (this.isGrouped()) { for (AvpRepresentation child : this.getChildren()) { String childStr = child.toString().replace("\n", "\n---"); sb.append("\n---" + childStr); } } return sb.toString(); } @Override public int hashCode() { // code+vendor is enough by AVP def final int prime = 31; int result = 1; result = prime * result + code; result = prime * result + (int) (vendor ^ (vendor >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } // code+vendor is enough by AVP def AvpRepresentationImpl other = (AvpRepresentationImpl) obj; if (code != other.code) { return false; } if (vendor != other.vendor) { return false; } return true; } @Override public Object clone() throws CloneNotSupportedException { AvpRepresentationImpl clone = new AvpRepresentationImpl(); clone.allowed = this.allowed; clone.code = this.code; clone.grouped = this.grouped; clone.multiplicityIndicator = this.multiplicityIndicator; clone.name = this.name; clone.positionIndex = this.positionIndex; clone.vendor = this.vendor; clone.weak = this.weak; clone._mandatory = this._mandatory; clone._protected = this._protected; clone.description = this.description; clone.mayEncrypt = this.mayEncrypt; clone.ruleMandatory = this.ruleMandatory; clone.ruleProtected = this.ruleProtected; clone.ruleVendorBit = this.ruleVendorBit; clone.type = this.type; List<AvpRepresentation> cloneChildren = new ArrayList<AvpRepresentation>(); clone.children = cloneChildren; for (AvpRepresentation c : this.children) { cloneChildren.add((AvpRepresentation) c.clone()); } return clone; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.validation; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.jdiameter.api.Avp; import org.jdiameter.api.AvpSet; import org.jdiameter.api.Message; import org.jdiameter.api.validation.AvpNotAllowedException; import org.jdiameter.api.validation.AvpRepresentation; import org.jdiameter.api.validation.MessageRepresentation; import org.jdiameter.api.validation.ValidatorLevel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This class represents message/command in validation framework. It contains * basic info about command along with avp list - their multiplicity and * allowance. * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @since 1.5.4.0-build404 * */ public class MessageRepresentationImpl implements MessageRepresentation { private static transient Logger logger = LoggerFactory.getLogger(MessageRepresentationImpl.class); private int commandCode = -1; private long applicationId = 0; private boolean isRequest = false; protected Map<AvpRepresentation, AvpRepresentation> unmuttableMessageAvps = new HashMap<AvpRepresentation, AvpRepresentation>(); private String name = null; public MessageRepresentationImpl(int commandCode, long applicationId, boolean isRequest) { super(); this.commandCode = commandCode; this.applicationId = applicationId; this.isRequest = isRequest; } public MessageRepresentationImpl(int commandCode, boolean isRequest) { this(commandCode, 0, isRequest); } public MessageRepresentationImpl(int commandCode, long applicationId, boolean isRequest, String name) { super(); this.commandCode = commandCode; this.applicationId = applicationId; this.isRequest = isRequest; this.name = name; } public MessageRepresentationImpl(MessageRepresentationImpl clone) { super(); this.applicationId = clone.applicationId; this.commandCode = clone.commandCode; this.isRequest = clone.isRequest; this.name = clone.name; // TODO: copy avps? } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (applicationId ^ (applicationId >>> 32)); result = prime * result + commandCode; result = prime * result + (isRequest ? 1231 : 1237); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } MessageRepresentationImpl other = (MessageRepresentationImpl) obj; if (applicationId != other.applicationId) { return false; } if (commandCode != other.commandCode) { return false; } if (isRequest != other.isRequest) { return false; } return true; } public Map<AvpRepresentation, AvpRepresentation> getMessageAvps() { return unmuttableMessageAvps; } public void setMessageAvps(Map<AvpRepresentation, AvpRepresentation> messageAvps) { //this.unmuttableMessageAvps = Collections.unmodifiableMap(messageAvps); this.unmuttableMessageAvps = messageAvps; } public int getCommandCode() { return commandCode; } public long getApplicationId() { return applicationId; } public boolean isRequest() { return isRequest; } public String getName() { return name; } public AvpRepresentation getAvp(int code) { return getAvp(code, 0); } public AvpRepresentation getAvp(int code, long vendorId) { AvpRepresentation avp = unmuttableMessageAvps.get(new AvpRepresentationImpl(code, vendorId)); if (avp == null) { logger.warn("AVP with code " + code + " and Vendor-Id " + vendorId + " not present in Message Representation!"); } return avp; } // Convenience methods ------------------------------------------------------ public boolean isAllowed(int code, long vendorId) { AvpRepresentation avpRep = new AvpRepresentationImpl(code, vendorId); avpRep = this.unmuttableMessageAvps.get(avpRep); if (avpRep == null) { return true; } return avpRep.isAllowed(); } public boolean isAllowed(int code) { return this.isAllowed(code, 0); } public boolean isCountValidForMultiplicity(int code, int avpCount) { return this.isCountValidForMultiplicity(code, 0, avpCount); } public boolean isCountValidForMultiplicity(int code, long vendorId, int avpCount) { AvpRepresentation avpRep = getAvp(code, vendorId); if (avpRep == null) { return true; } return avpRep.isCountValidForMultiplicity(avpCount); } public boolean isCountValidForMultiplicity(AvpSet destination, int code, long vendorId) { return this.isCountValidForMultiplicity(destination, code,vendorId,0); } public boolean isCountValidForMultiplicity(AvpSet destination, int code) { return this.isCountValidForMultiplicity(destination, code,0L); } public boolean isCountValidForMultiplicity(AvpSet destination, int code, long vendorId, int numberToAdd) { AvpRepresentation avpRep = getAvp(code, vendorId); if (avpRep == null) { return true; } return avpRep.isCountValidForMultiplicity(destination, numberToAdd); } public boolean isCountValidForMultiplicity(AvpSet destination, int code, int numberToAdd) { return this.isCountValidForMultiplicity(destination, code, 0, numberToAdd); } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(MessageRepresentation o) { if (o == this) { return 0; } if (o == null) { return 1; } return this.hashCode() - o.hashCode(); } @Override public Object clone() throws CloneNotSupportedException { MessageRepresentationImpl clone = (MessageRepresentationImpl) super.clone(); clone.applicationId = this.applicationId; clone.commandCode = this.commandCode; clone.isRequest = this.isRequest; clone.name = this.name; // clone.messageAvps = new HashMap<AvpRepresentation, // AvpRepresentation>(); Map<AvpRepresentation, AvpRepresentation> map = new HashMap<AvpRepresentation, AvpRepresentation>(); for (Entry<AvpRepresentation, AvpRepresentation> entry : this.unmuttableMessageAvps.entrySet()) { map.put((AvpRepresentation) entry.getKey().clone(), (AvpRepresentation) entry.getValue().clone()); } clone.setMessageAvps(map); return clone; } @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append(isRequest ? "Request" : "Answer").append(" code: ").append(this.commandCode).append(" applicationId: ").append(this.applicationId) .append(" name: ").append(this.name); for (AvpRepresentation childAvp : this.getMessageAvps().values()) { sb.append("\n").append(childAvp.toString()); } return sb.toString(); } // Validation part ---------------------------------------------------------- public void validate(Message msg, ValidatorLevel validatorLevel) throws AvpNotAllowedException { if (validatorLevel == ValidatorLevel.OFF) { return; } // if its !OFF, we will go down, at least to this section for (AvpRepresentation ap : this.unmuttableMessageAvps.values()) { AvpSet innerSet = msg.getAvps().getAvps(ap.getCode(), ap.getVendorId()); int count = 0; if (innerSet != null) { count = innerSet.size(); } if (!ap.isCountValidForMultiplicity(count)) { throw new AvpNotAllowedException("AVP: \n" + ap + "\n,has wrong count in message - " + (count), ap.getCode(), ap.getVendorId()); } // if its ALL, we need to go down deeper in AVPs if (validatorLevel != ValidatorLevel.ALL) { continue; } if (count != 0 && ap.isGrouped()) { // we are grouped validateGrouped(ap, innerSet); } } } /** * @param ap * @param innerSet */ private void validateGrouped(AvpRepresentation ap, AvpSet innerSet) { // we have set of grouped avps, and ap is grouped, lets validate // NOTE this methods can be called multiple time, until we dont have for (int index = 0; index < innerSet.size(); index++) { Avp presumablyGrouped = innerSet.getAvpByIndex(index); ap.validate(presumablyGrouped); // AvpSet groupedPart = null; // try { // groupedPart = presumablyGrouped.getGrouped(); // } // catch (AvpDataException e) { // logger.debug("Failed to get grouped AVP.", e); // } // // if (groupedPart == null) { // logger.error("Avp should be grouped, but its not: " + ap); // // continue; // } // else { // validateGroupedChildren(ap, groupedPart); // } } } // /** // * @param ap // * @param presumablyGrouped // */ // private void validateGroupedChildren(AvpRepresentation ap, AvpSet groupedAvp) { // // we have grouped avp, and its representation, we should validate // // children. // for (AvpRepresentation childrenVAvp : ap.getChildren()) { // AvpSet childSset = groupedAvp.getAvps(childrenVAvp.getCode(), childrenVAvp.getVendorId()); // int count = childSset.size(); // // if (!childrenVAvp.isCountValidForMultiplicity(count)) { // throw new AvpNotAllowedException("AVP: " + childrenVAvp + " has wrong count ,in grouped parent avp - " + (count) + ", allowed: " // + childrenVAvp.getMultiplicityIndicator(), ap.getCode(), ap.getVendorId()); // } // if (childrenVAvp.isGrouped()) { // // validateGrouped(childrenVAvp, childSset); // } // // else we are good ? // } // // } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.validation; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.jdiameter.api.Message; import org.jdiameter.api.validation.AvpNotAllowedException; import org.jdiameter.api.validation.AvpRepresentation; import org.jdiameter.api.validation.Dictionary; import org.jdiameter.api.validation.MessageRepresentation; import org.jdiameter.api.validation.ValidatorLevel; import org.jdiameter.client.impl.DictionarySingleton; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * Implementation of {@link Dictionary} interface. * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @since 1.5.4.0-build404 */ public class DictionaryImpl implements Dictionary { private static transient Logger logger = LoggerFactory.getLogger(DictionaryImpl.class); public static final Dictionary INSTANCE = new DictionaryImpl("dictionary.xml"); private static final String UNDEFINED_AVP_TYPE = "UNDEFINED"; private static final String AVP_DEFAULT_INDEX = "-1"; private static final String AVP_DEFAULT_MULTIPLICITY = AvpRepresentation._MP_ZERO_OR_MORE; public static final String _AVP_ATTRIBUTE_NAME = "name"; public static final String _AVP_ATTRIBUTE_CODE = "code"; public static final String _AVP_ATTRIBUTE_VENDOR = "vendor"; public static final String _AVP_ATTRIBUTE_MULTIPLICITY = "multiplicity"; public static final String _AVP_ATTRIBUTE_INDEX = "index"; private Map<AvpRepresentation, AvpRepresentation> avpMap = new HashMap<AvpRepresentation, AvpRepresentation>(); private Map<String, AvpRepresentation> avpByNameMap = new HashMap<String, AvpRepresentation>(); private Map<String, String> vendorMap = new HashMap<String, String>(); private Map<MessageRepresentation, MessageRepresentation> commandMap = new HashMap<MessageRepresentation, MessageRepresentation>(); private Map<String, String> typedefMap = new HashMap<String, String>(); private boolean configured = false; private DictionaryImpl(String confFile) { this.init(confFile); } private void init(String confFile) { InputStream is = null; try { is = DictionarySingleton.class.getResourceAsStream(confFile); if(is == null) { logger.debug("Failed to locate dictionary configuration file: {}, in class classloader. Trying thread context class loader.", confFile); is = Thread.currentThread().getContextClassLoader().getResourceAsStream(confFile); } if(is == null) { logger.debug("Failed to locate dictionary configuration file: {}, in thread context class loader. Trying using 'config/' prefix.", confFile); is = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/" + confFile); } if(is == null) { logger.debug("Failed to locate dictionary configuration file: {}, in thread context class loader. Trying regular file.", confFile); File fDict = new File(confFile); if(fDict.exists()) { is = new FileInputStream(fDict); } else { logger.debug("Failed to locate dictionary configuration file: {}, from regular file. Trying using 'config/' prefix.", confFile); fDict = new File("config/" + confFile); if(fDict.exists()) { is = new FileInputStream(fDict); } } } if(is != null) { this.configure(is); } else { this.setEnabled(false); logger.warn("Failed to initialize and configure Diameter Dictionary since configuration file was not found. Validator is disabled."); } } catch(FileNotFoundException fnfe) { logger.debug("Could not load configuration file: {}, from any known location.", confFile); } finally { if(is != null) { try { is.close(); } catch (IOException e) { logger.error("", e); } } } } // Parser functions --------------------------------------------------------- /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#configure(java.io.InputStream) */ public void configure(InputStream is) { if (is == null) { logger.error("No input stream to configure dictionary from?"); return; } try { long startTime = System.currentTimeMillis(); this.avpByNameMap = new TreeMap<String, AvpRepresentation>(new Comparator<String>() { public int compare(String o1, String o2) { return (o1 == null) ? 1 : (o2 == null) ? -1 : o1.compareTo(o2); } }); this.vendorMap = new HashMap<String, String>(); this.typedefMap = new HashMap<String, String>(); this.avpMap = new HashMap<AvpRepresentation, AvpRepresentation>(); this.commandMap = new HashMap<MessageRepresentation, MessageRepresentation>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(is); doc.getDocumentElement().normalize(); this.parseVendors(doc); this.parseTypeDefs(doc); this.parseAvps(doc); this.parseCommands(doc); this.configured = true; long endTime = System.currentTimeMillis(); if(logger.isInfoEnabled()) { logger.info("Mobicents Diameter Dictionary loaded in {}ms -- Vendors[{}] Commands[{}] Types[{}] AVPs[{}]", new Object[] { (endTime - startTime), vendorMap.size(), commandMap.size(), typedefMap.size(), avpMap.size() }); } if (logger.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); int c = 0; for (AvpRepresentation key : this.avpMap.keySet()) { if (this.avpMap.get(key).isWeak()) { c++; sb.append("---------------------------------\n").append("Found incomplete AVP definition:\n").append(this.avpMap.get(key)).append("\n"); } } if (c > 0) { sb.append("------- TOTAL INCOMPLETE AVPS COUNT: ").append(c).append(" -------"); logger.info(sb.toString()); } } } catch (Exception e) { this.enabled = false; this.configured = false; logger.error("Failed to parse validator configuration. Validator disabled.", e); } finally { // close? try { is.close(); } catch (IOException e) { logger.debug("Failed to close InputStream for Dictionary XML.", e); } } } /** * Parses the <vendor /> attributes from a Dictionary XML Document * * @param doc the DOM object representing the XML Document with the Dictionary definitions */ protected void parseVendors(Document doc) { // Parse vendors, we will need those. // Format: <vendor vendor-id="TGPP" code="10415" name="3GPP" /> NodeList vendorNodes = doc.getElementsByTagName("vendor"); for (int v = 0; v < vendorNodes.getLength(); v++) { Node vendorNode = vendorNodes.item(v); if (vendorNode.getNodeType() == Node.ELEMENT_NODE) { Element vendorElement = (Element) vendorNode; // Get the Code (number) and ID (string) String vendorCode = vendorElement.getAttribute("code"); String vendorId = vendorElement.getAttribute("vendor-id"); vendorMap.put(vendorId, vendorCode); } } } /** * Parses the <typedefn /> attributes from a Dictionary XML Document * * @param doc the DOM object representing the XML Document with the Dictionary definitions */ protected void parseTypeDefs(Document doc) { // Parse type definitions. Handy to match against defined AVP types // and to fill AVPs with generic function. // Format: <typedefn type-name="Integer32" /> // <typedefn type-name="Enumerated" type-parent="Integer32" /> NodeList typedefNodes = doc.getElementsByTagName("typedefn"); for (int td = 0; td < typedefNodes.getLength(); td++) { Node typedefNode = typedefNodes.item(td); if (typedefNode.getNodeType() == Node.ELEMENT_NODE) { Element typedefElement = (Element) typedefNode; String typeName = typedefElement.getAttribute("type-name"); String typeParent = typedefElement.getAttribute("type-parent"); // UTF8String and Time are special situations, we don't want to convert these. if (typeParent == null || typeParent.equals("") || typeName.equals("UTF8String") || typeName.equals("Time")) { typeParent = typeName; } typedefMap.put(typeName, typeParent); } } } /** * Parses the <typedefn /> attributes from a Dictionary XML Document * * @param doc the DOM object representing the XML Document with the Dictionary definitions */ protected void parseAvps(Document doc) { // Format: <avpdefn name="Talk-Burst-Volume" code="1256" vendor-id="TGPP" mandatory="must" protected="may" may-encrypt="true" vendor-bit="must" > // <type type-name="Unsigned32" /> // </avpdefn> NodeList avpDefnNodes = doc.getElementsByTagName("avpdefn"); for (int i = 0; i < avpDefnNodes.getLength(); i++) { Node avpNode = avpDefnNodes.item(i); Element avpDefnElement = (Element) avpNode; String avpName = avpDefnElement.getAttribute("name"); String avpCode = avpDefnElement.getAttribute("code"); String avpVendorId = avpDefnElement.getAttribute("vendor-id"); String avpMandatory = avpDefnElement.getAttribute("mandatory"); String avpProtected = avpDefnElement.getAttribute("protected").equals("") ? "may" : avpDefnElement.getAttribute("protected"); String avpMayEncrypt = avpDefnElement.getAttribute("may-encrypt"); String avpVendorBit = avpDefnElement.getAttribute("vendor-bit"); long vendorCode = getVendorCode(avpVendorId); // Let's figure out the type // It can be: // <type type-name="UTF8String" /> // OR // <grouped> <avp name="PoC-Change-Time" multiplicity="1" /> ... </grouped> // OR // <type type-name="Enumerated"> <enum code="0" name="MULTICAST" /> ... </enumerated> String avpType = UNDEFINED_AVP_TYPE; List<AvpRepresentation> groupedAvpChilds = new ArrayList<AvpRepresentation>(); NodeList avpDefnChildNodes = avpNode.getChildNodes(); for (int j = 0; j < avpDefnChildNodes.getLength(); j++) { Node avpDefnChildNode = avpDefnChildNodes.item(j); if (avpDefnChildNode.getNodeType() == Node.ELEMENT_NODE) { Element avpDefnChildElement = (Element) avpDefnChildNode; if (avpDefnChildElement.getNodeName().equals("grouped")) { avpType = "Grouped"; // Let's fetch the childs // Format: <avp name="PoC-Change-Time" multiplicity="1" /> NodeList groupedAvpMembers = avpDefnChildElement.getChildNodes(); for (int gChildIndex = 0; gChildIndex < groupedAvpMembers.getLength(); gChildIndex++) { Node groupedAvpChildNode = groupedAvpMembers.item(gChildIndex); if (groupedAvpChildNode.getNodeType() == Node.ELEMENT_NODE) { Element groupedAvpChildElement = (Element) groupedAvpChildNode; String childName = null; String childMultiplicity = AVP_DEFAULT_MULTIPLICITY; String childIndexIndicator = AVP_DEFAULT_INDEX; if (!groupedAvpChildElement.hasAttribute("name")) { if (logger.isDebugEnabled()) { logger.debug(new StringBuffer("[ERROR] Grouped child does not have name, grouped avp: Name[").append(avpName).append("] Description["). append("").append("] Code[").append(avpCode).append("] May-Encrypt[").append(avpMayEncrypt).append("] Mandatory["). append(avpMandatory).append("] Protected [").append(avpProtected).append("] Vendor-Bit [").append(avpVendorBit).append("] Vendor-Id ["). append(avpVendorId).append("] Constrained[").append("").append("] Type [").append(avpType).append("]").toString()); } continue; } else { childName = groupedAvpChildElement.getAttribute("name"); } childMultiplicity = groupedAvpChildElement.hasAttribute("multiplicity") ? groupedAvpChildElement.getAttribute("multiplicity") : AvpRepresentation._MP_ZERO_OR_MORE; childIndexIndicator = groupedAvpChildElement.hasAttribute("index") ? groupedAvpChildElement.getAttribute("index") : "-1"; // have we parsed this child definition already? AvpRepresentation childRep = this.avpByNameMap.get(childName); AvpRepresentationImpl child = null; if(childRep != null) { try { child = (AvpRepresentationImpl) childRep.clone(); } catch (CloneNotSupportedException cnse) { // It should not happen, but anyway if(logger.isWarnEnabled()) { logger.warn("Unable to clone AVP " + childRep, cnse); } } } else { child = new AvpRepresentationImpl(childName, vendorCode); child.markWeak(true); } child.setMultiplicityIndicator(childMultiplicity); child.markFixPosition(Integer.valueOf(childIndexIndicator)); groupedAvpChilds.add(child); } } } else if (avpDefnChildElement.getNodeName().equals("type")) { avpType = avpDefnChildElement.getAttribute("type-name"); //FIXME: baranowb: why this is like that? This changes type of AVP to primitive ONE..? Checks against type dont make sense, ie to check for Address type... avpType = typedefMap.get(avpType); if(avpType == null) { logger.warn("Unknown AVP Type ({}) for AVP with code {} and vendor-id {} ", new Object[] { avpDefnChildElement.getAttribute("type-name"), avpCode, avpVendorId}); } } else { logger.warn("Unknown AVP Definition child element for AVP with code {} and vendor-id {} ", avpCode, avpVendorId); } } } try { AvpRepresentationImpl avp = null; avp = new AvpRepresentationImpl(avpName, "N/A", Integer.valueOf(avpCode), avpMayEncrypt.equals("yes"), avpMandatory, avpProtected, avpVendorBit, vendorCode, avpType); if (avp.isGrouped()) { avp.setChildren(groupedAvpChilds); // we are not strong enough, children are referenced ONLY by name, so we are // weak until all children can be resolved to strong representation avp.markWeak(true); } resolveWeakLinks(avp); AvpRepresentation existingAvp = null; if((existingAvp = avpMap.get(avp)) != null) { logger.warn("Duplicated AVP Definition for AVP Code: {}, Vendor-Id: {}. See TRACE logs for definitions.", avp.getCode(), avp.getVendorId()); logger.trace("Existing AVP:\r\n {}\r\n New AVP:\r\n {}", existingAvp, avp); } else { avpMap.put(avp, avp); } AvpRepresentation oldAvp = avpByNameMap.put(avp.getName(), avp); if(oldAvp != null) { logger.debug("[WARN] Overwrited definition of AVP with the same name: Old: {}, New: {}", new Object[] { oldAvp, avp }); } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug(new StringBuffer("[ERROR] Failed Parsing AVP: Name[").append(avpName).append("] Description[").append("N/A").append("] Code[").append(avpCode).append("] May-Encrypt[").append(avpMayEncrypt).append("] Mandatory[").append(avpMandatory).append("] Protected [").append(avpProtected).append("] Vendor-Bit [").append(avpVendorBit).append("] Vendor-Id [").append(avpVendorId).append("] Constrained[").append("N/A").append("] Type [").append(avpType).append("]").toString(), e); } } } for(AvpRepresentation rep : avpMap.values()) { markWeaks((AvpRepresentationImpl) rep); } } private boolean markWeaks(AvpRepresentationImpl rep) { if(rep.isGrouped()) { boolean isWeak = false; for(AvpRepresentation repC : rep.getChildren()) { if(markWeaks((AvpRepresentationImpl) repC)) { isWeak = true; } } rep.markWeak(isWeak); } else { rep.markWeak(rep.getCode() == -1); } return rep.isWeak(); } /** * For a given AVP resolves the weak links (where AVP definition in grouped * AVPs is not yet known, and only added by Name) * * @param newAvp the AVP which was just defined */ private void resolveWeakLinks(AvpRepresentation newAvp) { for(AvpRepresentation avp : avpMap.values()) { if(avp.isGrouped()) { if(avp.getName().equals(newAvp.getName())) { continue; } List<AvpRepresentation> avpChilds = avp.getChildren(); for(int n = 0; n < avpChilds.size(); n++) { AvpRepresentation avpChild = avpChilds.get(n); if(avpChild.getName().equals(newAvp.getName())) { try { AvpRepresentationImpl strongAvp = (AvpRepresentationImpl) newAvp.clone(); strongAvp.setMultiplicityIndicator(avpChild.getMultiplicityIndicator()); strongAvp.markFixPosition(avpChild.getPositionIndex()); strongAvp.markWeak(false); avpChilds.set(n, strongAvp); resolveWeakLinks(avp); } catch (CloneNotSupportedException cnse) { // It should not happen, but anyway if(logger.isWarnEnabled()) { logger.warn("Unable to clone AVP " + newAvp, cnse); } } } } } } } /** * @param doc * @param nameToCode * @param avpMap * @return */ private void parseCommands(Document doc) { // here all grouped AVPs should have proper filling. // now lets go through message definition, we have to respect application nodes NodeList applicationNodes = doc.getElementsByTagName("application"); // Map<MessageRepresentation, MessageRepresentation> commandMap = new // HashMap<MessageRepresentation, MessageRepresentation>(); for (int applicationIndex = 0; applicationIndex < applicationNodes.getLength(); applicationIndex++) { if (applicationNodes.item(applicationIndex).getNodeType() == Node.ELEMENT_NODE) { Element applicationElement = (Element) applicationNodes.item(applicationIndex); if (!applicationElement.hasAttribute("id")) { logger.debug("[ERROR] Application definition does not have ID, skipping message"); continue; } long applicationCode = Long.valueOf(applicationElement.getAttribute("id")); NodeList commandNodes = applicationElement.getElementsByTagName("command"); for (int c = 0; c < commandNodes.getLength(); c++) { Node commandNode = commandNodes.item(c); if (commandNode.getNodeType() == Node.ELEMENT_NODE) { Element commandElement = (Element) commandNode; if (!commandElement.hasAttribute("request")) { logger.debug("[ERROR] Command for application: {} does not define if its request or answer, skipping.", applicationCode); continue; } String commandName = commandElement.getAttribute("name"); String commandCode = commandElement.getAttribute("code"); String isRequest = commandElement.getAttribute("request"); MessageRepresentationImpl msg = new MessageRepresentationImpl(Integer.valueOf(commandCode), applicationCode, Boolean.parseBoolean(isRequest), commandName); Map<AvpRepresentation, AvpRepresentation> commandAvpList = new HashMap<AvpRepresentation, AvpRepresentation>(); commandMap.put(msg, msg); // now we have to process avp defs for this message :) NodeList commandAvpsList = commandElement.getElementsByTagName("avp"); for (int commandAvpIndex = 0; commandAvpIndex < commandAvpsList.getLength(); commandAvpIndex++) { if (commandAvpsList.item(commandAvpIndex).getNodeType() == Node.ELEMENT_NODE) { Element commandAvpElement = (Element) commandAvpsList.item(commandAvpIndex); String multiplicity = null; String name = null; String index = null; if (!commandAvpElement.hasAttribute("name")) { logger.debug("[ERROR] Command defines avp without name! Command: {}, Code: {}, ApplicationID: {}", new Object[] { msg.getName(), msg.getCommandCode(), msg.getApplicationId() }); continue; } else { name = commandAvpElement.getAttribute("name"); } if (!commandAvpElement.hasAttribute("multiplicity")) { logger.debug("[WARN] Command defines avp without multiplicity."); multiplicity = AvpRepresentation._MP_ZERO_OR_MORE; } else { multiplicity = commandAvpElement.getAttribute("multiplicity"); } index = commandAvpElement.hasAttribute("index") ? commandAvpElement.getAttribute("index") : "-1"; String avpCode = commandAvpElement.getAttribute("code"); String avpVendor = commandAvpElement.getAttribute("vendor"); if (avpCode == null) { logger.debug("[ERROR] Command defines avp without code! Command: {}, Code: {}, ApplicationID: {}", new Object[] { msg.getName(), msg.getCommandCode(), msg.getApplicationId() }); continue; } if (avpVendor == null) { logger.debug("[WARN] Command defines avp without vendor, assuming default. Command: {}, Code: {}, ApplicationID: {}", new Object[] { msg.getName(), msg.getCommandCode(), msg.getApplicationId() }); avpVendor = "0"; } // here we have name and multiplicity. we have to get avp def from name, clone and set multiplicity. AvpRepresentation strongRepresentation = null; AvpRepresentation strongKey = getMapKey(Integer.valueOf(avpCode), Long.valueOf(avpVendor)); strongRepresentation = this.avpMap.get(strongKey); if (strongRepresentation != null && !strongRepresentation.isWeak()) { AvpRepresentationImpl clone; try { clone = (AvpRepresentationImpl) strongRepresentation.clone(); clone.setMultiplicityIndicator(multiplicity); clone.markFixPosition(Integer.valueOf(index)); commandAvpList.put(clone, clone); } catch (CloneNotSupportedException cnse) { // It should not happen, but anyway if(logger.isWarnEnabled()) { logger.warn("Unable to clone AVP " + strongRepresentation, cnse); } } } else { logger.debug("[WARN] No strong avp for key {}, in name: {}", new Object[] {strongKey, name}); continue; } } } msg.setMessageAvps(commandAvpList); } } } } } /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#isConfigured() */ public boolean isConfigured() { return this.configured; } public AvpRepresentation getAvp(int code) { return getAvp(code, 0); } public AvpRepresentation getAvp(int code, long vendorId) { if (!this.configured) { return null; } AvpRepresentation avp = avpMap.get(getMapKey(code, vendorId)); if (avp == null) { logger.warn("AVP with code {} and Vendor-Id {} not present in dictionary!", code, vendorId); } return avp; } public AvpRepresentation getAvp(String avpName) { return this.configured ? avpByNameMap.get(avpName) : null; } private long getVendorCode(String vendorId) { long value = -1; if (vendorId == null) { value = 0; } else { String vendorCode = vendorMap.get(vendorId); value = vendorCode == null ? 0 : Long.parseLong(vendorCode); } return value; } private AvpRepresentation getMapKey(int avpCode, long vendorId) { return new AvpRepresentationImpl(avpCode, vendorId); } /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#getMessage(int, boolean) */ public MessageRepresentation getMessage(int commandCode, boolean isRequest) { return this.getMessage(commandCode, 0, isRequest); } /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#getMessage(int, long, boolean) */ public MessageRepresentation getMessage(int commandCode, long applicationId, boolean isRequest) { if (!this.configured) { return null; } MessageRepresentation key = new MessageRepresentationImpl(commandCode, applicationId, isRequest); return this.commandMap.get(key); } // Validation --------------------------------------------------------------- private boolean enabled = true; private ValidatorLevel sendValidationLevel = ValidatorLevel.ALL; private ValidatorLevel receiveValidationLevel = ValidatorLevel.OFF; /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#isValidate() */ public boolean isEnabled() { return this.enabled; } /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#getSendLevel() */ public ValidatorLevel getSendLevel() { return this.sendValidationLevel; } /* * (non-Javadoc) * * @see org.jdiameter.api.validation.Dictionary#getReceiveLevel() */ public ValidatorLevel getReceiveLevel() { return this.receiveValidationLevel; } public void setSendLevel(ValidatorLevel level) { this.sendValidationLevel = level; } public void setReceiveLevel(ValidatorLevel level) { this.receiveValidationLevel = level; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public void setConfigured(boolean configured) { this.configured = configured; } public void validate(Message msg, boolean incoming) throws AvpNotAllowedException { if (!enabled || !configured) { return; } MessageRepresentationImpl rep = new MessageRepresentationImpl(msg.getCommandCode(), msg.getApplicationId(), msg.isRequest()); rep = (MessageRepresentationImpl) this.commandMap.get(rep); if (rep == null) { // no notion, lets leave it. logger.warn("Validation could not be performed, command not defined!. Code={}, Application-Id={}, Req={}", new Object[] { msg.getCommandCode(), msg.getApplicationId(), msg.isRequest() }); return; } rep.validate(msg, (incoming ? receiveValidationLevel : sendValidationLevel)); } // Helper methods ----------------------------------------------------------- public Map<AvpRepresentation, AvpRepresentation> getAvpMap() { return avpMap; } public Map<String, String> getVendorMap() { return vendorMap; } public Map<MessageRepresentation, MessageRepresentation> getCommandMap() { return commandMap; } public Map<String, String> getTypedefMap() { return typedefMap; } public Map<String, AvpRepresentation> getNameToCodeMap() { return avpByNameMap; } protected void printAvpTree(AvpRepresentation rep, String tab) { String x = tab + "+-- " + rep.getCode() + "/" + rep.getVendorId(); while(x.length() < 25) { x += "."; } System.out.println(x + rep.getName() + " > " + rep.getType()); if(rep.isGrouped()) { for(AvpRepresentation repC : rep.getChildren()) { printAvpTree(repC, " " + tab); } } } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.statistic; import java.util.concurrent.ConcurrentLinkedQueue; import org.jdiameter.api.StatisticRecord; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticRecord; import org.jdiameter.common.api.statistic.IStatisticRecord.Counters; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class StatisticImpl implements IStatistic { protected boolean enable = true; protected ConcurrentLinkedQueue<StatisticRecord> records = new ConcurrentLinkedQueue<StatisticRecord>(); protected String name; protected String description; protected IStatistic.Groups group; public String getName() { return name; } public String getDescription() { return description; } public StatisticImpl(String name) { this.name = name; } public StatisticImpl(String name, IStatistic.Groups group) { this(group.name()+"."+name); this.group = group; this.description = group.getDescription(); } // public StatisticImpl(String name, String desctiprion, IStatisticRecord... rec) { // this.name = name; // this.description = desctiprion; // for (IStatisticRecord r : rec) { // records.add((IStatisticRecord) r); // } // } public StatisticImpl(String name, IStatistic.Groups group,String desctiprion, IStatisticRecord... rec) { this(name,group); this.description = desctiprion; for (IStatisticRecord r : rec) { records.add((IStatisticRecord) r); } } public void appendCounter(IStatisticRecord... rec) { for (IStatisticRecord r : rec) { r.enable(this.enable); records.add(r); } } public IStatisticRecord getRecordByName(String name) { for (StatisticRecord r : records) { if (r.getName().equals(name)) { return (IStatisticRecord) r; } } return null; } public IStatisticRecord getRecordByName(Counters name) { for (StatisticRecord r : records) { if (r.getName().equals(name.toString())) { return (IStatisticRecord) r; } } return null; } public void enable(boolean e) { for (StatisticRecord r : records) { r.enable(e); } enable = e; } public boolean isEnabled() { return enable; } public void reset() { for (StatisticRecord r : records) { r.reset(); } } public StatisticRecord[] getRecords() { return records.toArray(new StatisticRecord[0]); } public String toString() { return "Statistic{" + " records=" + records + " }"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((group == null) ? 0 : group.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; StatisticImpl other = (StatisticImpl) obj; if (group != other.group) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.statistic; import static org.jdiameter.common.api.concurrent.IConcurrentFactory.ScheduledExecServices.StatisticTimer; import java.util.HashMap; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.jdiameter.api.Configuration; import org.jdiameter.api.StatisticRecord; import org.jdiameter.common.api.concurrent.IConcurrentFactory; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticManager; import org.jdiameter.common.api.statistic.IStatisticProcessor; import org.jdiameter.common.api.statistic.IStatisticRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Statistics Processor * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class StatisticProcessorImpl implements IStatisticProcessor { private static final Logger logger = LoggerFactory.getLogger(StatisticProcessorImpl.class); private ScheduledExecutorService executorService; private IConcurrentFactory concurrentFactory; private IStatisticManager statisticFactory; // statics for logger names private static final String STATS_ROOT_LOGGER_NAME = "jdiameter.statistic"; private static final String STATS_LOGGER_PREFIX = "jdiameter.statistic."; // future for actions to update per second stats private Future<?> processorFuture; // future for logger runnable private Future<?> logFuture; // map of loggers, so we dont have to fetch from slf all the time private HashMap<String, Logger> loggers = new HashMap<String, Logger>(); public StatisticProcessorImpl(Configuration config, IConcurrentFactory concurrentFactory, final IStatisticManager statisticFactory) { this.statisticFactory = statisticFactory; this.concurrentFactory = concurrentFactory; } public void start() { if (!this.statisticFactory.isOn()) { return; } this.executorService = concurrentFactory.getScheduledExecutorService(StatisticTimer.name()); // start processor this.processorFuture = this.executorService.scheduleAtFixedRate(new Runnable() { public void run() { try { for (IStatisticRecord r : ((StatisticManagerImpl) statisticFactory).getPSStatisticRecord()) { StatisticRecord[] recs = r.getChilds(); // magic of PS records, there are two children created... IStatisticRecord realRecord = (IStatisticRecord) recs[0]; IStatisticRecord prevRecord = (IStatisticRecord) recs[1]; r.setLongValue(realRecord.getValueAsLong() - prevRecord.getValueAsLong()); prevRecord.setLongValue(realRecord.getValueAsLong()); } } catch (Exception e) { logger.warn("Can not start persecond statistic", e); } } }, 0, 1, TimeUnit.SECONDS); // start logging actions this.logFuture = this.executorService.scheduleAtFixedRate(new Runnable() { public void run() { boolean oneLine = false; for (IStatistic statistic : statisticFactory.getStatistic()) { if (statistic.isEnabled()) { for (StatisticRecord record : statistic.getRecords()) { oneLine = true; String loggerKey = statistic.getName() + "." + record.getName(); Logger logger = null; if ((logger = loggers.get(loggerKey)) == null) { logger = LoggerFactory.getLogger(STATS_LOGGER_PREFIX + loggerKey); loggers.put(loggerKey, logger); } if (logger.isTraceEnabled()) { logger.trace(record.toString()); } } } } if (oneLine) { Logger logger = null; if ((logger = loggers.get(STATS_ROOT_LOGGER_NAME)) == null) { logger = LoggerFactory.getLogger(STATS_ROOT_LOGGER_NAME); loggers.put(STATS_ROOT_LOGGER_NAME, logger); } if (logger.isTraceEnabled()) { logger.trace("=============================================== Marker ==============================================="); } } } }, statisticFactory.getPause(), statisticFactory.getDelay(), TimeUnit.MILLISECONDS); } public void stop() { if (!this.statisticFactory.isOn()) { return; } if(this.processorFuture!=null) { this.processorFuture.cancel(false); this.processorFuture = null; } if(this.logFuture != null) { this.logFuture.cancel(false); this.logFuture = null; } this.concurrentFactory.shutdownNow(executorService); } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.statistic; import java.util.Arrays; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicLong; import org.jdiameter.api.StatisticRecord; import org.jdiameter.common.api.statistic.IStatisticRecord; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ class StatisticRecordImpl implements IStatisticRecord { protected boolean enable = true; protected String name; protected String description; protected Counters counter; protected AtomicLong value; protected ConcurrentLinkedQueue<StatisticRecord> childs = new ConcurrentLinkedQueue<StatisticRecord>(); protected ValueHolder valueHolder; public StatisticRecordImpl(String name) { this.name = name; this.value = new AtomicLong(0); } public StatisticRecordImpl(String name, String description) { this(name); this.description = description; } public StatisticRecordImpl(String name, Counters counter) { this(counter.name()+"."+name); this.counter = counter; this.description = counter.getDescription(); } public StatisticRecordImpl(String name, String description, IStatisticRecord... childs) { this(name, description); this.childs.addAll(Arrays.asList(childs)); } public StatisticRecordImpl(String name, String description, ValueHolder valueHolder) { this(name, description); this.valueHolder = valueHolder; } public StatisticRecordImpl(String name, String description, ValueHolder valueHolder, IStatisticRecord... childs) { this(name, description, valueHolder); this.childs.addAll(Arrays.asList(childs)); } public StatisticRecordImpl(String name, String description, long value) { this(name, description); this.value = new AtomicLong(value); } public String getName() { return name; } public String getDescription() { return description; } public int getValueAsInt() { return valueHolder != null ? ((IntegerValueHolder) valueHolder).getValueAsInt() : (int) value.get(); } public double getValueAsDouble() { return valueHolder != null ? ((DoubleValueHolder) valueHolder).getValueAsDouble() : Double.longBitsToDouble(value.get()); } public long getValueAsLong() { return valueHolder != null ? ((LongValueHolder) valueHolder).getValueAsLong() : value.get(); } public void inc() { if (enable) { this.value.incrementAndGet(); } } public void inc(long delta) { if (enable) { this.value.addAndGet(delta); } } public void setDoubleValue(double value) { if (enable) { this.value.set(Double.doubleToLongBits(value)); } } public void setLongValue(long value) { if (enable) { this.value.set(value); } } public void dec() { if (enable) { value.decrementAndGet(); } } public StatisticRecord[] getChilds() { return childs.toArray(new StatisticRecord[0]); } public void reset() { value.set(0); } public void enable(boolean e) { for (StatisticRecord r : childs) { r.enable(e); } enable = e; } public boolean isEnabled() { return this.enable; } public String toString() { return String.valueOf(valueHolder != null ? valueHolder.getValueAsString() : value.get()); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((counter == null) ? 0 : counter.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; StatisticRecordImpl other = (StatisticRecordImpl) obj; if (counter != other.counter) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.impl.statistic; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import org.jdiameter.api.Configuration; import org.jdiameter.client.impl.helpers.Parameters; import org.jdiameter.common.api.statistic.IStatistic; import org.jdiameter.common.api.statistic.IStatisticManager; import org.jdiameter.common.api.statistic.IStatisticRecord; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public class StatisticManagerImpl implements IStatisticManager { //TODO: remove CopyOnWrite.... private List<IStatistic> allStatistic = new CopyOnWriteArrayList<IStatistic>(); private List<IStatisticRecord> allPSStatisticRecord = new CopyOnWriteArrayList<IStatisticRecord>(); private List<IStatistic> frozenAllStatistic = Collections.unmodifiableList(allStatistic); private List<IStatisticRecord> frozenAllPSStatisticRecord = Collections.unmodifiableList(allPSStatisticRecord); private boolean enabled; private long pause, delay; private Set<String> activeRecords; //list of stats enabled on start public StatisticManagerImpl(Configuration config) { long pause = (Long) Parameters.StatisticsLoggerPause.defValue(); long delay = (Long) Parameters.StatisticsLoggerDelay.defValue(); boolean enabled = (Boolean) Parameters.StatisticsEnabled.defValue(); String activeRecords = (String) Parameters.Statistics.defValue(); Configuration[] loggerParams = config.getChildren(Parameters.Statistics.ordinal()); if (loggerParams != null && loggerParams.length > 0) { pause = loggerParams[0].getLongValue(Parameters.StatisticsLoggerPause.ordinal(), pause); delay = loggerParams[0].getLongValue(Parameters.StatisticsLoggerDelay.ordinal(), delay); enabled = loggerParams[0].getBooleanValue(Parameters.StatisticsEnabled.ordinal(), enabled); activeRecords = loggerParams[0].getStringValue(Parameters.StatisticsActiveList.ordinal(), activeRecords); } this.pause = pause; this.delay = delay; this.enabled = enabled; Set<String> enabledSet = new HashSet<String>(); if(activeRecords != null && activeRecords.length()>0) { for(String s:activeRecords.split(",")) { enabledSet.add(s); } } this.activeRecords = Collections.unmodifiableSet(enabledSet); } public IStatisticRecord newCounterRecord(IStatisticRecord.Counters recordDescription) { StatisticRecordImpl statisticRecord = new StatisticRecordImpl(recordDescription.name(), recordDescription.getDescription()); statisticRecord.enable(this.isEnabled(recordDescription.name())); return statisticRecord; } public IStatisticRecord newCounterRecord(IStatisticRecord.Counters recordDescription, IStatisticRecord.ValueHolder counters) { StatisticRecordImpl statisticRecord = new StatisticRecordImpl(recordDescription.name(), recordDescription.getDescription(), counters); statisticRecord.enable(this.isEnabled(recordDescription.name())); return statisticRecord; } public IStatisticRecord newCounterRecord(IStatisticRecord.Counters recordDescription, IStatisticRecord.ValueHolder counter, IStatisticRecord... rec) { StatisticRecordImpl statisticRecord = new StatisticRecordImpl(recordDescription.name(), recordDescription.getDescription(), counter, rec); statisticRecord.enable(this.isEnabled(recordDescription.name())); return statisticRecord; } public IStatisticRecord newCounterRecord(String name, String description) { StatisticRecordImpl statisticRecord = new StatisticRecordImpl(name, description); statisticRecord.enable(this.isEnabled(name)); return statisticRecord; } public IStatisticRecord newCounterRecord(String name, String description, IStatisticRecord.ValueHolder counters) { StatisticRecordImpl statisticRecord = new StatisticRecordImpl(name, description, counters); statisticRecord.enable(this.isEnabled(name)); return statisticRecord; } public IStatisticRecord newPerSecondCounterRecord(String name,IStatisticRecord.Counters recordDescription, IStatisticRecord child) { IStatisticRecord prevValue = new StatisticRecordImpl(name, recordDescription.getDescription()); IStatisticRecord psStatistic = new StatisticRecordImpl(recordDescription.name()+"."+name, recordDescription.getDescription(), child, prevValue); if(allPSStatisticRecord.contains(psStatistic)) { throw new IllegalArgumentException("Statistic already defined: "+psStatistic); } allPSStatisticRecord.add(psStatistic); return psStatistic; } public IStatistic newStatistic(String name, IStatistic.Groups group, IStatisticRecord... rec) { IStatistic statistic = new StatisticImpl(name,group, group.getDescription(), rec); statistic.enable(this.isEnabled(statistic.getName())); if(allStatistic.contains(statistic)) { throw new IllegalArgumentException("Statistic already defined: "+statistic); } allStatistic.add(statistic); return statistic; } // public IStatistic newStatistic(String name, String description, IStatisticRecord... rec) { // //FIXME: remove this? // IStatistic statistic = new StatisticImpl(name, description, rec); // statistic.enable(this.isEnabled(statistic.getName())); // if(allStatistic.contains(statistic)) // { // throw new IllegalArgumentException("Statistic already defined: "+statistic); // } // allStatistic.add(statistic); // return statistic; // } // // public void removePerSecondCounterRecord(String name,IStatisticRecord.Counters recordDescription) // { // IStatisticRecord record = new StatisticRecordImpl(recordDescription+"."+name,recordDescription.getDescription()); // this.allPSStatisticRecord.remove(record); // } // // public void removeStatistic(String name) // { // IStatistic statistic = new StatisticImpl(name); // this.allStatistic.remove(statistic); // } // // public void removeStatistic(String name, IStatistic.Groups group) // { // IStatistic statistic = new StatisticImpl(name,group); // this.allStatistic.remove(statistic); // } public void removePerSecondCounterRecord(IStatisticRecord rec) { this.allPSStatisticRecord.remove(rec); } public void removeStatistic(IStatistic stat) { this.allStatistic.remove(stat); } private boolean isEnabled(String name) { if(this.activeRecords.contains(name)) { return true; } //else lets check prefixes. while(name.indexOf(".")>0) { name = name.substring(0,name.lastIndexOf(".")); if(this.activeRecords.contains(name)) { return true; } } return this.activeRecords.contains(name); } public boolean isOn() { return enabled; } public long getPause() { return pause; } public long getDelay() { return delay; } public Set<String> getEnabled() { return activeRecords; } public List<IStatisticRecord> getPSStatisticRecord(){ return this.frozenAllPSStatisticRecord; } public List<IStatistic> getStatistic(){ return this.frozenAllStatistic; } // Exception in thread "Timer-0" java.lang.NullPointerException // at org.jdiameter.client.impl.fsm.PeerFSMImpl$2.getValueAsDouble(PeerFSMImpl.java:107) // at org.jdiameter.client.impl.fsm.PeerFSMImpl$2.getValueAsString(PeerFSMImpl.java:119) // at org.jdiameter.common.impl.statistic.StatisticRecordImpl.toString(StatisticRecordImpl.java:125) // at java.lang.String.valueOf(String.java:2826) // at java.lang.StringBuilder.append(StringBuilder.java:115) // at java.util.AbstractCollection.toString(AbstractCollection.java:422) // at java.lang.String.valueOf(String.java:2826) // at java.lang.StringBuilder.append(StringBuilder.java:115) // at org.jdiameter.common.impl.statistic.StatisticImpl.toString(StatisticImpl.java:89) // at java.lang.String.valueOf(String.java:2826) // at java.lang.StringBuilder.append(StringBuilder.java:115) // at org.jdiameter.common.impl.statistic.StatisticManagerImpl.print(StatisticManagerImpl.java:209) // at org.jdiameter.common.impl.statistic.StatisticManagerImpl.access$0(StatisticManagerImpl.java:204) // at org.jdiameter.common.impl.statistic.StatisticManagerImpl$1.run(StatisticManagerImpl.java:48) // at java.util.TimerThread.mainLoop(Timer.java:512) // at java.util.TimerThread.run(Timer.java:462) }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.api.timer; import java.io.Serializable; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public interface ITimerFacility { public Serializable schedule(String sessionId, String timerName, long miliseconds) throws IllegalArgumentException; public void cancel(Serializable id); }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2010, 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.jdiameter.common.api.data; import org.jdiameter.api.BaseSession; import org.jdiameter.api.NetworkReqListener; import org.jdiameter.common.api.app.IAppSessionData; import org.jdiameter.common.api.app.IAppSessionDataFactory; /** * * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> */ public interface ISessionDatasource { void start(); void stop(); public boolean exists(String sessionId); public NetworkReqListener getSessionListener(String sessionId); public void setSessionListener(String sessionId, NetworkReqListener data); public NetworkReqListener removeSessionListener(String sessionId); public void removeSession(String sessionId); public void addSession(BaseSession session); public BaseSession getSession(String sessionId); public boolean isClustered(); public IAppSessionDataFactory<? extends IAppSessionData> getDataFactory(Class<? extends IAppSessionData> x); }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.api.app.sh; import org.jdiameter.api.Answer; import org.jdiameter.api.Request; import org.jdiameter.api.app.AppAnswerEvent; import org.jdiameter.api.app.AppRequestEvent; public interface IShMessageFactory { AppRequestEvent createProfileUpdateRequest(Request request); AppRequestEvent createPushNotificationRequest(Request request); AppRequestEvent createSubscribeNotificationsRequest(Request request); AppRequestEvent createUserDataRequest(Request request); AppAnswerEvent createProfileUpdateAnswer(Answer answer); AppAnswerEvent createPushNotificationAnswer(Answer answer); AppAnswerEvent createSubscribeNotificationsAnswer(Answer answer); AppAnswerEvent createUserDataAnswer(Answer answer); long getApplicationId(); long getMessageTimeout(); }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.api.app.sh; import org.jdiameter.common.api.app.IAppSessionData; /** * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public interface IShSessionData extends IAppSessionData { // marker interface }
Java
/* * JBoss, Home of Professional Open Source * Copyright 2008, 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.jdiameter.common.api.app.sh; import org.jdiameter.api.app.AppSession; import org.jdiameter.api.app.StateChangeListener; import org.jdiameter.api.sh.ClientShSessionListener; import org.jdiameter.api.sh.ServerShSessionListener; import org.jdiameter.common.api.app.IAppSessionFactory; /** * Diameter Sh Session Factory * * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a> * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a> */ public interface IShSessionFactory extends IAppSessionFactory { public void setClientShSessionListener(ClientShSessionListener v); public ClientShSessionListener getClientShSessionListener(); public void setServerShSessionListener(ServerShSessionListener v); public ServerShSessionListener getServerShSessionListener(); public void setStateChangeListener(StateChangeListener<AppSession> v); public StateChangeListener<AppSession> getStateChangeListener(); public void setMessageFactory(IShMessageFactory factory); public IShMessageFactory getMessageFactory(); }
Java