001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.q2.iso; 020 021import org.jpos.core.Configurable; 022import org.jpos.core.Configuration; 023import org.jpos.core.ConfigurationException; 024import org.jpos.iso.ISOException; 025import org.jpos.iso.ISOMsg; 026import org.jpos.iso.ISOResponseListener; 027 028import java.rmi.RemoteException; 029import java.rmi.registry.LocateRegistry; 030import java.rmi.registry.Registry; 031import java.rmi.server.*; 032 033/** 034 * RMI QMUX Proxy 035 * @author Mark Salter 036 * @author Alejandro Revilla 037 * @author Niclas Hedhman 038 * @version $Revision: 2854 $ $Date: 2010-01-02 10:34:31 +0000 (Sat, 02 Jan 2010) $ 039 * @since 1.4.9 040 */ 041public class QMUXProxy implements RemoteQMUX, Configurable { 042 QMUX qmux; 043 private RemoteRef ref; 044 private RemoteStub stub; 045 /** 046 * Constructs an RMI-exported proxy for the given QMUX. 047 * 048 * @param qmux underlying MUX exposed over RMI 049 * @throws RemoteException if RMI export fails 050 */ 051 public QMUXProxy (QMUX qmux) throws RemoteException { 052 super(); 053 this.qmux = qmux; 054 startService (); 055 } 056 private void startService () throws RemoteException 057 { 058 try { 059 LocateRegistry.createRegistry (Registry.REGISTRY_PORT); 060 } catch (ExportException ignored) { 061 // NOPMD registry already exists 062 } 063 stub = UnicastRemoteObject.exportObject (this); 064 ref = stub.getRef(); 065 } 066 public boolean isConnected() { 067 return qmux.isConnected(); 068 } 069 public ISOMsg request(ISOMsg m, long timeout) throws ISOException { 070 return qmux.request(m, timeout); 071 } 072 public void request(ISOMsg m, long timeout, ISOResponseListener rl, 073 Object handBack) throws ISOException { 074 qmux.request(m, timeout, rl, handBack); 075 076 } 077 public void setConfiguration(Configuration cfg) 078 throws ConfigurationException { 079 qmux.setConfiguration(cfg); 080 081 } 082} 083