我有关于MBean和MXBean的以下问题:
我今天花了一些时间查看JBoss AS7.到目前为止我看到的东西给我留下了深刻的印象,但我注意到好的'JMX-Console不再存在.
我何时选择部署为JBoss SAR而不是EAR?
这是一个更普遍的问题,我正在寻找解释每个部署模型的优缺点的指南,以及哪一个适用.
我想将startup MBEAN文件(startup-client-service.xml)从我的EJB> META-INF,移动到EAR> META-INF文件夹.我试着用了maven-resources-plugin插件,但它只是从文件中复制EJB> META-INF到Target的ear文件夹中.但在内置ear的startup-client-service.xml文件不在可用META-INF
如何将我的启动文件移动到META-INF到ear> META-INF?
这是耳朵的pom文件.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.testapp</groupId>
<artifactId>my-client-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>Test app EAR</name>
<artifactId>my-client-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>com.testapp</groupId>
<artifactId>my-client-ejb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals> …Run Code Online (Sandbox Code Playgroud) 我们目前正在将一些项目从JBoss 4.x移植到JBoss 7.到目前为止,除了我们通常用于提供简单管理操作的MBean之外,一切似乎都运行正常.
我一直在寻找相当长的一段时间,但要么我无法提出正确的搜索术语,要么我缺少一些知识来弥补JBoss 4.x和JBoss 7中的MBean定义之间的差距.
因此,希望有人可以提供我可能缺少的内容或我必须阅读的内容(可能是一些文档,示例等)的提示
在Jboss 4.x中,我们的MBean通常如下所示:
@Service( objectName = "Domain:Name=SomeMBean",
xmbean="resource:<path-to-xmbean.xml>")
class SomeMBean
{
@EJB
private SomeService someService;
public String someOperation()
{
someService.doSomething();
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)
我们使用@Service注释来定义对象名称和xmbean描述符,JBoss会自动注册那些mbeans.
显然,在JBoss 7中,@Service注释不再存在,因此需要另一种方法.
到目前为止,我设法用平台mbean服务器手动注册MBean,但我更喜欢JBoss自动执行此操作.另外,到目前为止,我还没有设法提供方法/参数的描述(尽管这些功能更加出色).
为了清楚起见,我会重复这个问题:
如何在JBoss 7(Java EE 6)中定义提供以下功能的MBean?
更新
这是我到目前为止所得到的:
首先,我发现了这个投影,它使用CDI来包装相应注释的任何bean的注入目标,并在postConstruct()方法中进行JMX注册:http://code.google.com/p/jmx-annotations/.此外,扫描找到的MBean以获取类/属性/方法/参数注释,这些注释提供注释属性的描述.
但是,postConstruct()似乎没有为EJB调用该方法(我假设这是为了不与EJB容器冲突).因此MBean现在不应该是EJB而是普通的CDI bean.
因此,具有MBean不会自动实例化的缺点.为了解决这个问题,有一个单例bean在启动时循环遍历所有bean,BeanManager并创建每个找到的MBean的实例.由于MBean仍然具有其注入目标,postConstruct()因此不会调用其方法,并且将在MBean服务器中注册该bean.
以下是启动过程的概述:
postConstruct()将调用MBean的注入目标的方法,因此MBean在MBean服务器中注册此方法的一个缺点是在执行MBean方法时缺少事务上下文(任何EJB调用都将在事务上下文中运行).但是,如果需要,可以使用CDI拦截器修复这个问题,该拦截器将提供事务上下文.Seam项目似乎有适当的拦截器.
我仍然不确定这是否是一种理智和稳定的方法,因此任何建设性的评论,提示等都非常受欢迎.
我正在尝试使类实现MBean接口,以便我可以在运行时询问属性.我试图询问的课程如下
public class ProfileCache implements ProfileCacheInterfaceMBean{
private Logger logger = Logger.getLogger(ProfileCache.class);
private ConcurrentMap<String, Profile> cache;
public ProfileCache(ConcurrentMap<String, Profile> cache){
this.cache = cache;
}
/**
* Update the cache entry for a given user id
* @param userid the user id to update for
* @param profile the new profile to store
* @return true if the cache update
*/
public boolean updateCache(String userid, Profile profile) {
if (cache == null || cache.size() == 0) {
throw new RuntimeException("Unable to update …Run Code Online (Sandbox Code Playgroud) 我正在使用JBoss运行客户端/服务器应用程序.
如何连接到服务器JVM的MBeanServer?我想使用MemoryMX MBean来跟踪内存消耗.
我可以使用JNDI查找连接到JBoss MBeanServer,但java.lang.MemoryMX MBean未在JBoss MBeanServer中注册.
编辑:要求从客户端以编程方式访问内存使用情况.
在启动时,我们需要获取正在运行的应用程序的服务器地址和http端口.到现在为止我们这样做了:
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName socketBindingMBean = new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http");
String host = (String) mBeanServer.getAttribute(socketBindingMBean, "boundAddress"),
Integer port = (Integer) mBeanServer.getAttribute(socketBindingMBean, "boundPort"));
Run Code Online (Sandbox Code Playgroud)
一切都很好但是从jBoss 7.1.1.Final迁移到7.1.3.Final后我们遇到了MBean未在服务器启动时定义的问题.这意味着如果我在已经运行的 jboss服务器上部署应用程序,一切都很好,但如果我启动服务器并且在服务器启动期间加载了应用程序MBean不在那里.
我不知道为什么,但我觉得jBoss确保在大多数MBean之前启动/加载应用程序.我看了一眼,发现在申请后加载了Mbeans:
所以,
使用以下选项启动Java应用程序时:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=0
-Dcom.sun.management.jmxremote.local.only=false
Run Code Online (Sandbox Code Playgroud)
Java使用短暂的端口,这对于避免冲突非常有用.
是否可以从应用程序中以编程方式获取实际端口(或连接URL)?
有什么不同:
我们应该选择这两个组件中的任何一个来管理资源的优缺点是什么?