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.qbean; 020 021import org.jpos.q2.Q2; 022import org.jpos.q2.QBeanSupport; 023import org.jpos.space.LocalSpace; 024import org.jpos.space.Space; 025import org.jpos.space.SpaceFactory; 026 027import javax.management.ObjectName; 028import java.util.Set; 029 030/** 031 * Space Adaptor 032 * 033 * @author Alejandro Revilla 034 * @version $Revision$ $Date$ 035 */ 036 037public class SpaceAdaptor 038 extends QBeanSupport 039 implements SpaceAdaptorMBean 040{ 041 private Space sp = null; 042 private String spaceName = null; 043 private ObjectName objectName = null; 044 045 public SpaceAdaptor () { 046 super (); 047 } 048 049 protected void startService () throws Exception { 050 if (spaceName == null) 051 sp = SpaceFactory.getSpace (); 052 else 053 sp = SpaceFactory.getSpace (spaceName); 054 055 objectName = new ObjectName (Q2.QBEAN_NAME + 056 getName() + ",space=" + 057 (spaceName != null ? spaceName : "default") 058 ); 059 getServer().getMBeanServer().registerMBean (sp, objectName); 060 } 061 062 protected void stopService () throws Exception { 063 getServer().getMBeanServer().unregisterMBean (objectName); 064 } 065 066 public synchronized void setSpaceName (String spaceName) { 067 this.spaceName = spaceName; 068 setAttr (getAttrs (), "spaceName", spaceName); 069 setModified (true); 070 } 071 072 public String getSpaceName () { 073 return spaceName; 074 } 075 076 public Set getKeys () { 077 if (sp instanceof LocalSpace) 078 return ((LocalSpace)sp).getKeySet (); 079 return null; 080 } 081} 082