Recently I had faced a situation where I was forced to invoke a method on a particular “MBean” 10-15 times. I had completed this task manually from “JMX-Console”, but I didn’t feel it was elegant way of executing the task.
So I had started doing research to find out if there is better way of doing this task. Finally I found a utility called as “twiddle” which basically comes with every JBoss installation. In this article, I am just sharing information about what I had learned. There are many more complex tasks which can be performed with this utility.
Variables :-
JBOSS_HOME :- This is the location where JBoss is installed.
Prerequisites :-
We need to set “JAVA_HOME” variable before executing twiddle. This can be done in two ways.
Solution 1:-
In the Profile :- In “bash profile”(I use ‘bash’ profile, same can be done with other profiles), so go to “HOME” directory( enter “cd” at command prompt), open “.bash_profile(make sure there is “dot” before “bash_profile”, this is secret file) and enter below lines.
JAVA_HOME=<location where “java” is installed>
export JAVA_HOME
Save the file and enter “source .bash_profile”. “source” command reads commands from the file and executes in current shell environment.
Solution 2 :-
Update “twiddle.sh”(Take backup before editing the file).
Add below lines
JAVA_HOME=<location where “java” is installed>
export JAVA_HOME
echo “VAS JAVA_HOME : ${JAVA_HOME}”
Note :- Solution “2” is better than “1” because solution 1 might effect other applications too, but solution “2” will effect only “twiddle.sh”
Validation :-
Enter “echo ${JAVA_HOME}” , this should return the location where the JBoss is installed. If this variable returns “empty” value, then this variable is not set properly, please check above steps.
Execution :-
Go to the directory “JBOSS_HOME/bin” and execute “./twiddle.sh”. It should display the help options.
Help :-
./twiddle.sh –help-commands :- displays all the commands we can invoke on this utility.
./twiddle.sh –H<command> :- will provide additional information on particular command, such as syntax of the commands, options that can be passed to the command.
Example :-
./twiddle.sh -Hinvoke
Syntax :-
./twiddle.sh -s <serverUrl> -u <userName> -p <password> <command> [ command_arguments
serverUrl :- <protocol>://<serverName>:<port>
protocol :- jnp ( This is optional)
serverName :- Since we will be executing the command from the box where JBoss is installed, we can either give “localhost” or actual server name.
port :- 1099. This the port where Jboss Naming service is listening. If you are using out of box Jboss installation then this will be the port. But if you changed this and you don’t remember the port, then either check the file “JBOSS_HOME/server/<serverName>/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml” or log on to “http://<serverName>:<port>/jmx-console” and click on “jboss” on left column and then click “service=Naming” and the value for the attribute “port”.
Commands :-
jsr77 :- displays jsr77 related information.
xmbean :- print out mbean metadata as an “xmbean” descriptor. In this file you can find all attributes and operations on a particular mbean.
info :- get the metdata for an MBean.
get :- get value for an mbean attribute.
invoke :- invoke an operation on an MBean
create :- create an MBean
setattrs :- set the values of one or more MBean attributes
unregister :- unregister one or more MBeans
queryMethod :- query list of matchin methods on MBeans
listDomains :- list all the domains.
query :- query list of matching MBeans
set :- set the value for one MBean attribute
serverinfo :- get the information about MBean Server.
Examples :-
jsr77 :-
Displays the “jsr77” information for this particular server.
./twiddle.sh -s jnp://localhost:1099 -u admin -p admin jsr77
xmbean :-
Displays information of the MBean as “xmbean” descriptor.
./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming
info :-
Query attribute of a particular bean.
./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming
get :-
Get value of a particular ‘attribute’.
./twiddle.sh -s localhost:1099 -u admin -p admin get 'jboss:service=Naming' Name
Get value of a multiple ‘attributes’. The attributes must be separated by ‘Space’.
./twiddle.sh -s localhost:1099 -u admin -p admin get 'jboss:service=Naming' Name State
invoke :-
Invoke operation on a particular mbean.
./twiddle.sh -s localhost:1099 -u admin -p admin invoke jboss.system:type=ServerInfo listThreadCpuUtilization
Note :- There are multiple additional options, I didn’t explore them as of now.
create :-
Create an MBean.
I didn’t explore this command, I need to do research on this command a little more. I will update this article once I found more on this command.
setattrs :-
Set values of one or more bean attributes.
In below command we set values of two attributes “BackLog” and “JNPServerSocketFactoryBean” to “100” and “null” respectively.
./twiddle.sh -s localhost:1099 -u admin -p admin setattrs 'jboss:service=Naming' Backlog 100 JNPServerSocketFactory null
unregister :-
Unregister a one or more Mbeans.
Again I didn’t get much chance to explore this command, will update on this on this command once I am done with research.
queryMethod :-
Query all methods on all Mbeans.
./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod list
Query methods on few mbeans
./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod -f 'jboss:*' list
listDomains :-
List all the domains.
./twiddle.sh -s localhost:1099 -u admin -p admin listDomains
query :-
Display all Mbeans on the server.
./twiddle.sh -s localhost:1099 -u admin -p admin query '*:*'
Display MBeans on particular domain. In below command we display in the domain “jboss:j2ee”.
./twiddle.sh -s localhost:1099 -u admin -p admin query 'jboss.j2ee:*'
set :-
Set the value on particular attribute.
./twiddle.sh -s localhost:1099 -u admin -p admin set 'jboss.system:service=Logging,type=Log4jService' RefreshPeriod 60
serverinfo :-
Display information about MBean server.
./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -l
Number of MBeans on the server.
./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -c
Default Domain.
./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -d
Few Important Useful Operations :- We can do many operations with “Twiddle”, below are just few examples.
Deploying an Application :-
./twiddle.sh -s localhost:1099 -u admin -p admin invoke 'jboss.service:MainDeployer' deploy "file:///tmp/VASVijay/VASApp.war"
Undeploying an Application :-
./twiddle.sh -s localhost:1099 -u admin -p admin invoke 'jboss.service:MainDeployer' undeploy "file:///tmp/VASVijay/VASApp.war"
Redeploying an Application :-
./twiddle.sh -s localhost:1099 -u admin -p admin invoke 'jboss.service:MainDeployer' redeploy "file:///tmp/VASVijay/VASApp.war"
Take ThreadDump :-
./twiddle.sh -s localhost:1099 -u admin -p admin invoke 'jboss.system:type=ServerInfo' listThreadDump
Get Server Info :-
./twiddle.sh -s localhost:1099 -u admin -p admin get 'jboss.system:type=ServerInfo'
Issues :-
Twiddle will be throwing exception like below, this is a know nexception. This is because “twiddle” is executed on separate “JVM” from the “JBoss JVM”. There is patch for this at “https://issues.jboss.org/browse/JBAS-4323”
10:16:57,158 ERROR [Twiddle] Exec failed java.io.NotSerializableException: org.jboss.resource.connectionmanager.TxConnectionManager
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.ArrayList.writeObject(ArrayList.java:570)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
Pending Tasks :-
Exploring below commands and options :-
Options :- “-c” option. I was not able to find out correct way to execute this option, so I am checking out with Redhat on this option. If any one of you know how to use this option, please let me know. Thanks in advance for sharing the solution.
Commands :- “create” and “unregister” commands, I need to write code to explore these. I will soon add examples to execute these commands, once I test these commands successfully.
References :-
This article wouldn’t had been possible without ‘google’ and many wonderful articles written by experts. Few of them are below. I referenced many sites for this utility, I couldn’t remember all site names, If I didn’t mention any particular site name whose example I had used, its just that I don’t remember the site name, I sincerely apologize for not mentioning the site name. Please let know if any one feels I had missed to add any particular site in the reference, I will add the site to the references.
http://community.jboss.org/wiki/Twiddle
http://nagpals.com/jboss-examples-of-twiddle
I hope that you all liked this article, if there any issues or suggestions or if you don’t like anything in the article, please comment.
For some more Twiddle examples, refer the below post.
http://weblogic-wonders.com/weblogic/2011/02/13/twiddle-utility-examples/
Thanks,
Wonders-Team,
Dream, Learn, Share and Inspire !
分享到:
相关推荐
Jboss 项目部署文档 Jboss 项目部署文档是指在 Jboss 服务器上部署项目的详细步骤,包括环境变量的配置、项目打包、配置文件的修改、JNDI 的配置等。以下是 Jboss 项目部署文档的详细知识点: 一、环境变量配置 ...
【JBOSS,JBoss安装部署】 JBoss是Red Hat公司开发的一款开源的应用服务器,它基于Java EE(Enterprise Edition)规范,提供了全面的企业级应用程序部署和管理解决方案。本篇文章将详细讲解JBoss的安装和部署过程,...
【JBoss 应用服务器详解】 JBoss 是一个开源的、基于 J2EE(Java 2 Platform, Enterprise Edition)的应用服务器,由全球开发者社区共同维护和开发。它最初以 LGPL 许可协议发布,允许商业应用免费使用。2006年,...
JBoss AS 7.1.0.Final是在Linux环境下运行的一款开源Java应用服务器,由Red Hat公司维护。这个版本发布于2012年,它引入了许多改进和新特性,旨在提供更快的启动速度、更高的性能以及更好的模块化。在这个环境中,...
【标题】:“MyEclipse中配置JBoss” 在IT行业中,MyEclipse是一款深受开发者喜爱的集成开发环境(IDE),尤其对于Java EE项目开发来说,它提供了强大的支持。而JBoss则是一个开源的应用服务器,广泛用于部署和管理...
【JBoss 概述】 JBoss 是一个开源的、基于Java的、全面实现了J2EE规范的应用服务器。它提供了企业级的功能,如EJB(Enterprise JavaBeans)、JMS(Java Message Service)、JTS/JTA(Java Transaction Service / ...
JavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-...
"在IntelliJ IDEA 8中部署Jboss服务器图解" IntelliJ IDEA 8是 JetBrains 公司开发的一款功能强大且灵活的集成开发环境(IDE),它支持多种programming语言,包括Java、Python、Ruby、PHP等。Jboss则是一款流行的...
jboss配置入门 jboss系统是一种基于Java的应用服务器,具有高性能、可扩展、安全性强等特点。在本文中,我们将对jboss的基本配置进行介绍,包括其文件夹结构、配置文件、负载均衡配置等。 jboss文件夹结构 jboss的...
【JBoss EAP 7.2.6 补丁包详解】 JBoss Enterprise Application Platform (EAP) 是 Red Hat 提供的一款开源中间件,用于构建、部署和管理企业级 Java 应用程序。JBoss EAP 7.2.6 版本是一个重要的更新,包含了多个...
JBoss是著名的开源Java应用服务器,它基于Java EE(Enterprise Edition)规范,为开发者提供了全面的中间件服务。4.0.5.GA版本是JBoss的一个稳定版本,发布于2006年,适用于那些需要可靠且成熟的Java应用程序部署的...
JBoss是一款著名的开源Java应用服务器,它提供了许多企业级服务,包括事务管理、安全性和集群功能。在开发过程中,为了提高效率,我们通常希望在不中断应用服务的情况下更新部署的应用程序,这就是所谓的“热部署”...
本文档提供了jboss7开发和部署的详细指导,涵盖了jboss7的下载与安装、Eclipse中配置jboss7、项目部署和JNDI获取等方面的内容,旨在帮助开发者快速上手jboss7,并将jboss4.2版本平滑地移植到jboss7。
JBoss,作为一款开源的应用服务器,是Java EE(现在称为Jakarta EE)应用程序的重要运行环境。它由Red Hat公司维护,提供了对Web服务、EJB(Enterprise JavaBeans)、JMS(Java Message Service)等标准的全面支持。...
在JBoss 7及以上版本中,对EJB的配置过程相较于之前的版本有所变化,主要涉及到两个关键的配置文件:`jboss-ejb3.xml`和`ejb-jar.xml`。 `ejb-jar.xml`文件是EJB模块的标准配置文件,遵循Java EE规范。在这个文件中...
JBoss AS7 是一个开源的Java应用服务器,它是JBoss企业应用平台(EAP)的社区版本。JBoss AS7官方手册是关于如何配置、部署和管理JBoss AS7应用服务器的一份权威指南。该手册由Francesco Marchioni撰写,旨在帮助读者...
某大牛写的jboss-exp 1. 查看系统名称 java -jar jboss_exploit_fat.jar -i http://192.168.7.84:10081/invoker/JMXInvokerServlet get jboss.system:type=ServerInfo OSName 2. 查看系统版本 java -jar jboss_...