Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *        JacORB - a free Java ORB
   *
   *   Copyright (C) 1999-2012 Gerald Brose / The JacORB Team.
   *
   *   This library is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU Library General Public
   *   License as published by the Free Software Foundation; either
   *   version 2 of the License, or (at your option) any later version.
  *
  *   This library 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
  *   Library General Public License for more details.
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this library; if not, write to the Free
  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
 
 package org.jacorb.notification.jmx.jboss;
 
 
 
 import  org.jboss.iiop.CorbaORBService;
 import  org.jboss.mx.util.MBeanServerLocator;
 import  org.jboss.system.ServiceMBeanSupport;
Adaptor to run a JMX-enabled NotificationService inside of JBoss.

Author(s):
Alphonse Bendt
Jmx.mbean:
name = "JBossCOSNotificationService" extends = "org.jboss.system.ServiceMBean" persistPolicy = "OnUpdate" persistPeriod = "10" persistLocation = "${jboss.server.data.dir}" persistName = "COSNotification.ser" state-action-on-update = "keep-running" persistence-manager = "org.jboss.mx.persistence.ObjectStreamPersistenceManager"
Jboss.xmbean:
 
 public class JBossCOSNotificationService extends ServiceMBeanSupport implements
         JBossCOSNotificationServiceMBean, ObjectFactory
 {
     public final static String NAMING_NAME = "COSNotification";
 
     private static final String DEFAULT_DOMAIN = "NotificationService";
 
     private static final String NOT_RUNNING = "Not Started";
 
     private COSNotificationService delegate_;
 
     private String iorFileName_ = "CosNotification.ior";
 
     private String cosNamingEntry_ = "CosNotification";
 
     private String additionalArguments_;
 
     // operation from super interfaces
     // this is redundant but otherwise xmbean is not generated correctly
 
    

Jmx.managed:
attribute access = "read-only"
 
     public String getName()
     {
         return super.getName();
     }

    

Jmx.managed:
attribute access = "read-only"
 
     public int getState()
     {
         return super.getState();
     }

    

Jmx.managed:
attribute access = "read-only"
 
     public String getStateString()
     {
         return super.getStateString();
     }

    

:
-jmx.managed-operation description = "Detyped lifecycle invocation" impact = "ACTION"
    public void jbossInternalLifecycle(String methodthrows Exception
    {
        super.jbossInternalLifecycle(method);
    }

    

Jmx.managed:
operation description = "create the service, do expensive operations etc" impact = "ACTION"
    public void create() throws Exception
    {
        super.create();
    }

    

Jmx.managed:
operation description = "start the service, create is already called" impact = "ACTION"
    public void start() throws Exception
    {
        super.start();
    }

    

Jmx.managed:
operation description = "stop the service" impact = "ACTION"
    public void stop()
    {
        super.stop();
    }

    

Jmx.managed:
operation description = "destroy the service, tear down" impact = "ACTION"
    public void destroy()
    {
        super.destroy();
    }

    

Jmx.managed:
operation description="create a new channel" impact = "ACTION"
    public String createChannel()
    {
        return isStarted() ? .createChannel() : ;
    }

    

Jmx.managed:
attribute description = "NameService Entry (Optional)" access = "read-write"
    public String getCOSNamingEntry()
    {
        return ;
    }

    

Jmx.managed:
attribute access = "read-write"
    public void setCOSNamingEntry(String cosNamingEntry)
    {
         = cosNamingEntry;
        if (isStarted())
        {
            updateCOSNamingEntry();
        }
    }
    private void updateCOSNamingEntry()
    {
        log.info("Bound to COSNaming name: " + );
    }

    

Jmx.managed:
attribute description="Corbaloc to access the EventChannelFactory" access = "read-only"
    public String getCorbaloc()
    {
        return isStarted() ? .getCorbaloc() : ;
    }

    

Jmx.managed:
attribute description="IOR to access the EventChannelFactory" access = "read-only"
    public String getIOR()
    {
        return isStarted() ? .getIOR() : ;
    }

    

Jmx.managed:
attribute description = "Filename the IOR should be written to" access = "read-write"
    public String getIORFile()
    {
        return ;
    }

    

Jmx.managed:
attribute access = "read-write"
    public void setIORFile(String filenamethrows IOException
    {
         = filename;
        if (isStarted())
        {
            updateIORFile();
        }
    }
    private void updateIORFile() throws IOException
    {
        log.info("set IOR filename to " + );
    }

    

Jmx.managed:
attribute access = "read-write"
    public void setAdditionalArguments(String additionalArguments)
    {
         = additionalArguments;
    }

    

Jmx.managed:
attribute description = "Additional startup arguments. Setting these on an already running service will have no effect!" access = "read-write"
    {
        return ;
    }
    protected void startService() throws Exception
    {
        final ORB _orb;
        InitialContext _context = new InitialContext();
        try
        {
            _orb = (ORB_context.lookup("java:/" + CorbaORBService.ORB_NAME);
        } finally
        {
            _context.close();
        }
        String[] args = ConsoleMain.splitArgs();
         = new COSNotificationService(_orb, MBeanServerLocator.locateJBoss(),
                new JMXManageableXMBeanProvider(), args);
        bind("org.omg.CosNotifyChannelAdmin.EventChannelFactory");
        updateIORFile();
        updateCOSNamingEntry();
        .start();
        log.info("COSNotificationService started");
    }
    protected void stopService() throws Exception
    {
        .stop();
        unbind();
        log.info("COSNotificationService stopped");
    }
    public Object getObjectInstance(Object objName nameContext nameCtxHashtable environment)
            throws Exception
    {
        String s = name.toString();
        if (getLog().isTraceEnabled())
        {
            getLog().trace(
                    "getObjectInstance: obj.getClass().getName=\"" + obj.getClass().getName()
                            + "\n                   name=" + s);
        }
        if (.equals(s))
        {
            return .getEventChannelFactory();
        }
        throw new IllegalArgumentException();
    }
    private void bind(String nameString classNamethrows Exception
    {
        Reference _ref = new Reference(classNamegetClass().getName(), null);
        InitialContext _context = new InitialContext();
        try
        {
            _context.bind("java:/" + name_ref);
            log.info("Bound to JNDI name: " + name);
        } finally
        {
            _context.close();
        }
    }
    private void unbind(String namethrows Exception
    {
        InitialContext _context = new InitialContext();
        try
        {
            _context.unbind("java:/" + name);
        } finally
        {
            _context.close();
        }
    }
    private boolean isStarted()
    {
        return getState() == STARTED;
    }
New to GrepCode? Check out our FAQ X