Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFLY-11239] Refactoring SAR subsystem to don't use deprecated Servic…
…eBuilder methods.
- Loading branch information
Showing
12 changed files
with
477 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sar/src/main/java/org/jboss/as/service/DelegatingSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2018, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file 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.jboss.as.service; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a> | ||
*/ | ||
abstract class DelegatingSupplier implements Supplier<Object> { | ||
|
||
protected volatile Supplier<Object> objectSupplier; | ||
|
||
void setObjectSupplier(final Supplier<Object> objectSupplier) { | ||
this.objectSupplier = objectSupplier; | ||
} | ||
|
||
} |
44 changes: 0 additions & 44 deletions
44
sar/src/main/java/org/jboss/as/service/InjectedBeanMethodValue.java
This file was deleted.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
sar/src/main/java/org/jboss/as/service/MBeanRegistrationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file 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.jboss.as.service; | ||
|
||
import static org.jboss.as.service.logging.SarLogger.ROOT_LOGGER; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
import java.util.function.Supplier; | ||
import javax.management.MBeanServer; | ||
import javax.management.MalformedObjectNameException; | ||
import javax.management.ObjectName; | ||
|
||
import org.jboss.as.server.deployment.SetupAction; | ||
import org.jboss.msc.Service; | ||
import org.jboss.msc.service.ServiceName; | ||
import org.jboss.msc.service.StartContext; | ||
import org.jboss.msc.service.StartException; | ||
import org.jboss.msc.service.StopContext; | ||
|
||
/** | ||
* Service used to register and unregister an mbean with an mbean server. | ||
* | ||
* @author John Bailey | ||
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a> | ||
*/ | ||
final class MBeanRegistrationService implements Service { | ||
static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("mbean", "registration"); | ||
private final Supplier<MBeanServer> mBeanServerSupplier; | ||
private final Supplier<Object> objectSupplier; | ||
private final String name; | ||
private ObjectName objectName; | ||
private final List<SetupAction> setupActions; | ||
|
||
public MBeanRegistrationService(final String name, final List<SetupAction> setupActions, | ||
final Supplier<MBeanServer> mBeanServerSupplier, | ||
final Supplier<Object> objectSupplier) { | ||
this.name = name; | ||
this.setupActions = setupActions; | ||
this.mBeanServerSupplier = mBeanServerSupplier; | ||
this.objectSupplier = objectSupplier; | ||
} | ||
|
||
public synchronized void start(final StartContext context) throws StartException { | ||
final MBeanServer mBeanServer = getMBeanServer(); | ||
final Object value = objectSupplier.get(); | ||
try { | ||
objectName = new ObjectName(name); | ||
} catch (MalformedObjectNameException e) { | ||
throw ROOT_LOGGER.mbeanRegistrationFailed(e, name); | ||
} | ||
try { | ||
for (SetupAction action : setupActions) { | ||
action.setup(Collections.<String, Object>emptyMap()); | ||
} | ||
try { | ||
ROOT_LOGGER.debugf("Registering [%s] with name [%s]", value, objectName); | ||
mBeanServer.registerMBean(value, objectName); | ||
} catch (Exception e) { | ||
throw ROOT_LOGGER.mbeanRegistrationFailed(e, name); | ||
} | ||
} finally { | ||
ListIterator<SetupAction> it = setupActions.listIterator(setupActions.size()); | ||
while (it.hasPrevious()) { | ||
SetupAction action = it.previous(); | ||
action.teardown(Collections.<String, Object>emptyMap()); | ||
} | ||
} | ||
} | ||
|
||
public synchronized void stop(final StopContext context) { | ||
if (objectName == null) { | ||
ROOT_LOGGER.cannotUnregisterObject(); | ||
} | ||
final MBeanServer mBeanServer = getMBeanServer(); | ||
try { | ||
for (SetupAction action : setupActions) { | ||
action.setup(Collections.<String, Object>emptyMap()); | ||
} | ||
try { | ||
mBeanServer.unregisterMBean(objectName); | ||
} catch (Exception e) { | ||
ROOT_LOGGER.unregistrationFailure(e, objectName); | ||
} | ||
} finally { | ||
ListIterator<SetupAction> it = setupActions.listIterator(setupActions.size()); | ||
while (it.hasPrevious()) { | ||
SetupAction action = it.previous(); | ||
action.teardown(Collections.<String, Object>emptyMap()); | ||
} | ||
} | ||
} | ||
|
||
private MBeanServer getMBeanServer() { | ||
MBeanServer mBeanServer = mBeanServerSupplier.get(); | ||
if (mBeanServer == null) { | ||
mBeanServer = ManagementFactory.getPlatformMBeanServer(); | ||
} | ||
return mBeanServer; | ||
} | ||
|
||
} |
Oops, something went wrong.