5 methods of accessing GlassFish resources

Source: Internet
Author: User

Method 1, through the management console



First, create a database tutorial by using the Admin console connection pool Mypool. In the browser's input admin console address: localhost:4848. Login with the default username "admin" and its password "adminadmin". After you have successfully logged in, in the tree menu on the left, expand resources-JDBC-connection pooling.
In the main panel, click New. In the panel new JDBC Connection pool (step 1, 2 steps), enter name as Mypool, resource type selected as Javax.sql.DataSource, and database vendor selected JAVADB. In the next "New JDBC Connection pool (step 2, 2 steps)", you can see the default settings for the database connection pool. The idle timeout value in the pool settings column is changed from the default of 300 to 777. Click "Finish". At this point, we completed the creation of the database connection pool Mypook through the admin console and modified the value of its idle timeout.


Method 2, asadmin using the command line tool

Next, we view this resource through the command line Asadmin.
Asadmin List server.resource*
The results of the operation are as follows:

Undefined
Undefined
Server.resource
-
Ref
. jdbc
/
__callflowpool Server.resource
-
Ref
. jdbc
/
__timerpool Server.resource
-
Ref
. jdbc
/
__default server.resources SERVER.RESOURCES.JDBC
-
Connection
-
Pool. Derbypool SERVER.RESOURCES.JDBC
-
Connection
-
Pool.__callflowpool SERVER.RESOURCES.JDBC
-
Connection
-
Pool.__timerpool SERVER.RESOURCES.JDBC
-
Connection
-
Pool.mypool SERVER.RESOURCES.JDBC
-
Resource.jdbc
/
__callflowpool SERVER.RESOURCES.JDBC
-
Resource.jdbc
/
__timerpool SERVER.RESOURCES.JDBC
-
Resource.jdbc
/
__default

The Mbean listed here is identified by GlassFish own DottedName. The properties of the object Mypool are then viewed by Asadmin's subcommand:
Asadmin Get server.resources.jdbc-connection-pool.mypool.*
Or further view the property values of the idle timeout (idle-timeout-in-seconds).
Asadmin Get Server.resources.jdbc-connection-pool.mypool.idle-timeout-in-seconds


The results are as follows:
Server.resources.jdbc-connection-pool.mypool.idle-timeout-in-seconds = 777
At this point, we have completed the access to Mypool using the management tools of the command line Asadmin. Here Asadmin accesses the Mbean through the GlassFish extended dotted name naming method. Dotted name is a set of conventions defined by the GlassFish command-line tool asadmin. With the support of this set of conventions, the asadmin three subcommand (list, set, and get) can be passed through a "." The delimited string is addressed to an mbean in the GlassFish.


Method 3, through Third-party tools Jconsole


Next, we are going to access the object Mypool through Jconsole.
In the Jconsole login panel, select a remote process: localhost:8686 (8686 is the GlassFish default management port), the user name is also admin, password adminadmin. When you log in, you see information about the runtime of the GlassFish application server and click "MBean". Expand the tree structure "Com.sun.apps Tutorial Erv"-"Jdbc-connection-pool"-"My Pool"-"config"-"properties".
OK

See the information about the connection pool Mypool we care about. The value of the property Idle-timeout-in-seconds is 777. Modify 777 to 888.
When you return to the Admin console or command-line tool asadmin you can also see that the changes made just now in Jconsole are in effect.
The above description three tools are equivalent to the modification of glassfish resources.

The following is a programmatic way to access the database connection pool Mypool.


Method 4, through the standard JMX programming approach


The code for the standard JMX method is as follows: (The following is the demo code.) To highlight the focus, no exception handling. )


Undefined
Undefined
Import Javax.management.
*
; Import Javax.management.remote.
*
;
Public

Class
Jmx_demo {
Public
Jmx_demo () throws Exception {
//
Create a JMX URL

Jmxserviceurl URL
=

New
Jmxserviceurl (
"
Service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi
"
); Java.util.Map env
=

New
Java.util.Hashtable ();
//
Default user name and its password

String[] Creds
=
{
"
Admin
"
,
"
Adminadmin
"
}; Env.put (jmxconnector.credentials,creds);
//
Establish a connection

Jmxconnector Connector
=
Jmxconnectorfactory.connect (URL,ENV); Mbeanserverconnection MBSC
=
Connector.getmbeanserverconnection ();
//
The object Name of the Mbean to access

ObjectName Mbeanname
=

New
ObjectName (
"
Com.sun.appserv:type=jdbc-connection-pool,name=mypool,category=config
"
);
//
The property to be accessed Idle-timeout-in-seconds

System.
Out
. println (
"
Using JMX, JDBC Pool idle timeout:
"
+
Mbsc.getattribute (Mbeanname,
"
Idle-timeout-in-seconds
"
)); }
Public

Static

void
Main (final string[] args) throws exception{
New
Jmx_demo (); } }
The results of the operation are as follows: Using JMX, JDBC Pool idle timeout:888


Undefined
Undefined
Public

Class
Amx_demo {
Public
Amx_demo () throws Exception {
//
Machine name or IP address of Domain Admin server

Final String Host
=

"
localhost
"
;
//
JMX management port, default 8686.

Final
Int
Port
=
8686
;
//
Administrator name

Final String User
=

"
Admin
"
;
//
Administrator password

Final String Password
=

"
Adminadmin
"
; Tlsparams Tlsparams
=
Null
;
//
Connecting to JMX Server

AppserverConnectionSource Conn
=

New
AppserverConnectionSource (Appserverconnectionsource.protocol_rmi, host, port, user, password, tlsparams,
Null
); Conn.getjmxconnector (
True
);
//
Domainroot and JDBCConnectionPoolConfig are called DCP components domainroot mdomainroot = Conn.getdomainroot ();
//
Get a list of Jdbcconnectionpool

Map Pools
=
Mdomainroot.getdomainconfig (). Getjdbcconnectionpoolconfigmap (); JDBCConnectionPoolConfig Mypool
=
(jdbcconnectionpoolconfig) pools.
Get
(
"
Mypool
"
); System.
Out
. println (
"
Using DCP, JDBC Pool idle timeout:
"
+
Mypool.getidletimeoutinseconds ()); }
Public

Static

void
Main (final string[] args) throws exception{
New
Amx_demo (); Method 5, through the AMX programming method

The code for the AMX approach is as follows:


Undefined
undefined
  import com.sun.appserv.management.DomainRoot; import Com.sun.appserv.management.client.AppserverConnectionSource; Import Com.sun.appserv.management.client.TLSParams; Import Com.sun.appserv.management.util.misc.ExceptionUtil; Import Com.sun.appserv.management.config.
  *
  ; import java.net Tutorial. connectexception import Java.util.Map;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.