PageRenderTime 21ms CodeModel.GetById 7ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/MAPServiceBaseImpl.java

http://mobicents.googlecode.com/
Java | 178 lines | 85 code | 20 blank | 73 comment | 4 complexity | cd383b79948584f160f5e413abc52a4f MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.ss7.map;
 24
 25import java.util.List;
 26import java.util.concurrent.CopyOnWriteArrayList;
 27
 28import org.mobicents.protocols.ss7.map.api.MAPApplicationContext;
 29import org.mobicents.protocols.ss7.map.api.MAPException;
 30import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 31import org.mobicents.protocols.ss7.map.api.MAPProvider;
 32import org.mobicents.protocols.ss7.map.api.MAPDialog;
 33import org.mobicents.protocols.ss7.map.api.MAPServiceBase;
 34import org.mobicents.protocols.ss7.map.api.MAPServiceListener;
 35import org.mobicents.protocols.ss7.map.api.dialog.MAPProviderError;
 36import org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessage;
 37import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
 38import org.mobicents.protocols.ss7.tcap.api.TCAPException;
 39import org.mobicents.protocols.ss7.tcap.api.tc.dialog.Dialog;
 40import org.mobicents.protocols.ss7.tcap.asn.comp.ComponentType;
 41import org.mobicents.protocols.ss7.tcap.asn.comp.Invoke;
 42import org.mobicents.protocols.ss7.tcap.asn.comp.OperationCode;
 43import org.mobicents.protocols.ss7.tcap.asn.comp.Parameter;
 44import org.mobicents.protocols.ss7.tcap.asn.comp.Problem;
 45
 46/**
 47 * This class must be the super class of all MAP services
 48 * 
 49 * @author sergey vetyutnev
 50 * 
 51 */
 52public abstract class MAPServiceBaseImpl implements MAPServiceBase {
 53	protected Boolean _isActivated = false;
 54	//protected Set<MAPServiceListener> serviceListeners = new HashSet<MAPServiceListener>();
 55	protected List<MAPServiceListener> serviceListeners = new CopyOnWriteArrayList<MAPServiceListener>();
 56	protected MAPProviderImpl mapProviderImpl = null;
 57
 58	protected MAPServiceBaseImpl(MAPProviderImpl mapProviderImpl) {
 59		this.mapProviderImpl = mapProviderImpl;
 60	}
 61
 62	public MAPProvider getMAPProvider() {
 63		return this.mapProviderImpl;
 64	}
 65
 66	/**
 67	 * Creation a MAP Dialog implementation for the specific service
 68	 * 
 69	 * @param appCntx
 70	 * @param tcapDialog
 71	 * @return
 72	 */
 73	protected abstract MAPDialogImpl createNewDialogIncoming(MAPApplicationContext appCntx, Dialog tcapDialog);
 74
 75	/**
 76	 * Creating new outgoing TCAP Dialog. Used when creating a new outgoing MAP
 77	 * Dialog
 78	 * 
 79	 * @param origAddress
 80	 * @param destAddress
 81	 * @return
 82	 * @throws MAPException
 83	 */
 84	protected Dialog createNewTCAPDialog(SccpAddress origAddress, SccpAddress destAddress) throws MAPException {
 85		try {
 86			return this.mapProviderImpl.getTCAPProvider().getNewDialog(origAddress, destAddress);
 87		} catch (TCAPException e) {
 88			throw new MAPException(e.getMessage(), e);
 89		}
 90	}
 91
 92	
 93	public abstract void processComponent(ComponentType compType, OperationCode oc, Parameter parameter, MAPDialog mapDialog, Long invokeId, Long linkedId)
 94			throws MAPParsingComponentException;
 95	
 96	/**
 97	 * Adding MAP Dialog into MAPProviderImpl.dialogs Used when creating a new
 98	 * outgoing MAP Dialog
 99	 * 
100	 * @param dialog
101	 */
102	protected void putMAPDialogIntoCollection(MAPDialogImpl dialog) {
103		this.mapProviderImpl.addDialog((MAPDialogImpl) dialog);
104	}
105
106	protected void addMAPServiceListener(MAPServiceListener mapServiceListener) {
107		this.serviceListeners.add(mapServiceListener);
108	}
109
110	protected void removeMAPServiceListener(MAPServiceListener mapServiceListener) {
111		this.serviceListeners.remove(mapServiceListener);
112	}
113	/**
114	 * {@inheritDoc}
115	 */
116	public MAPApplicationContext getMAPv1ApplicationContext(int operationCode, Invoke invoke) {
117		return null;
118	}
119	
120	/**
121	 * This method is invoked when MAPProviderImpl.onInvokeTimeOut() is invoked.
122	 * An InvokeTimeOut may be a normal situation for the component class 2, 3,
123	 * or 4. In this case checkInvokeTimeOut() should return true and deliver to
124	 * the MAP-user correct indication
125	 * 
126	 * @param dialog
127	 * @param invoke
128	 * @return
129	 */
130	public boolean checkInvokeTimeOut(MAPDialog dialog, Invoke invoke) {
131		return false;
132	}
133	/**
134	 * {@inheritDoc}
135	 */
136	public boolean isActivated() {
137		return this._isActivated;
138	}
139	/**
140	 * {@inheritDoc}
141	 */
142	public void acivate() {
143		this._isActivated = true;
144	}
145	/**
146	 * {@inheritDoc}
147	 */
148	public void deactivate() {
149		this._isActivated = false;
150
151		// TODO: abort all active dialogs ?
152	}
153
154	protected void deliverErrorComponent(MAPDialog mapDialog, Long invokeId, MAPErrorMessage mapErrorMessage) {
155		for (MAPServiceListener serLis : this.serviceListeners) {
156			serLis.onErrorComponent(mapDialog, invokeId, mapErrorMessage);
157		}
158	}
159
160	protected void deliverRejectComponent(MAPDialog mapDialog, Long invokeId, Problem problem) {
161		for (MAPServiceListener serLis : this.serviceListeners) {
162			serLis.onRejectComponent(mapDialog, invokeId, problem);
163		}
164	}
165
166	protected void deliverProviderErrorComponent(MAPDialog mapDialog, Long invokeId, MAPProviderError providerError) {
167		for (MAPServiceListener serLis : this.serviceListeners) {
168			serLis.onProviderErrorComponent(mapDialog, invokeId, providerError);
169		}
170	}
171
172	protected void deliverInvokeTimeout(MAPDialog mapDialog, Invoke invoke) {
173		for (MAPServiceListener serLis : this.serviceListeners) {
174			serLis.onInvokeTimeout(mapDialog, invoke.getInvokeId());
175		}
176	}
177
178}