Learning Java Coding Language: Complete tutorial by Languages Informatic
Author:Languages, Informatic [Languages, Informatic]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2020-10-18T16:00:00+00:00
then switch to MBeans tab and find that MBean that we used in our Main class as an ObjectName (in the example above it's ServerManager ). In Attributes section we can see out attributes. If you specified get method only, attribute will be readable but not writeable. If you specified both get and set methods, attribute would be readable and writeable.
Specified methods can be invoked in Operations section.
If you want to be able to use remote management, you will need additional JVM parameters, like:
-Dcom.sun.management.jmxremote=true //true by default
-Dcom.sun.management.jmxremote.port=36006
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
These parameters can be found in Chapter 2 of JMX guides . After that you will be able to connect to your application via jConsole remotely with jconsole host:port or with specifying host:port or
service:jmx:rmi:///jndi/rmi://hostName:portNum/jmxrmi in jConsole GUI.
Useful links:
⢠JMX guides
⢠JMX Best practices Read JMX online: https://riptutorial.com/java/topic/9278/jmx
Chapter 98: JNDI
Examples
RMI through JNDI
This example shows how JNDI works in RMI. It has two roles:
⢠to provide the server with a bind/unbind/rebind API to the RMI Registry
⢠to provide the client with a lookup/list API to the RMI Registry.
The RMI Registry is part of RMI, not JNDI.
To make this simple, we will use java.rmi.registry.CreateRegistry() to create the RMI Registry.
1. Server.java(the JNDI server)
package com.neohope.jndi.test;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.util.Hashtable;
/**
* JNDI Server
* 1.create a registry on port 1234
* 2.bind JNDI
* 3.wait for connection
* 4.clean up and end
*/
public class Server {
private static Registry registry;
private static InitialContext ctx;
public static void initJNDI() {
try {
registry = LocateRegistry.createRegistry(1234);
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.rmi.registry.RegistryContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "rmi://localhost:1234"); ctx = new InitialContext(jndiProperties);
} catch (NamingException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public static void bindJNDI(String name, Object obj) throws NamingException { ctx.bind(name, obj); }
public static void unbindJNDI(String name) throws NamingException { ctx.unbind(name);
}
public static void unInitJNDI() throws NamingException { ctx.close();
}
public static void main(String[] args) throws NamingException, IOException { initJNDI();
NMessage msg = new NMessage("Just A Message");
bindJNDI("/neohope/jndi/test01", msg);
System.in.read();
unbindJNDI("/neohope/jndi/test01");
unInitJNDI();
}
}
2. Client.java(the JNDI client)
package com.neohope.jndi.test;
import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.Hashtable;
/**
* 1.init context
* 2.lookup registry for the service
* 3.use the service
* 4.end
*/
public class Client {
public static void main(String[] args) throws NamingException { final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.rmi.registry.RegistryContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "rmi://localhost:1234");
InitialContext ctx = new InitialContext(jndiProperties); NMessage msg = (NeoMessage) ctx.lookup("/neohope/jndi/test01"); System.out.println(msg.message);
ctx.close();
}
}
3. NMessage.java (RMI server class)
package com.neohope.jndi.test;
import java.io.Serializable; import java.rmi.Remote;
/** * NMessage
* RMI server class
* must implements Remote and Serializable
*/
public class NMessage implements Remote, Serializable { public String message = "";
public NMessage(String message)
{
this.message = message;
}
}
How to run the eaxmple:
1. build and start the server 2. build and start the client
Introduce
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(213070)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(102510)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(102037)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(101829)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74615)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50995)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40370)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40294)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40203)
Alkaline-earth metals promote propane dehydrogenation with carbon dioxide through geometric effects: Altering the reaction pathway by unknow(32812)
Induced iron vacancies boosting FeOOH loaded on sustainable Fenton-like collagen fiber membrane for efficient removal of emerging contaminants by unknow(32607)
Efficient electric-field-assisted photochemical conversion of methane to n-propanol exclusively over penetrated TiO2Ti hollow fibers by Guanghui Feng(32527)
Bi2SiO5 nanosheets as piezo-photocatalyst for efficient degradation of 2,4-Dichlorophenol by Hangyu Shi & Yifu Li & Lishan Zhang & Guoguan Liu & Qian Zhang & Xuan Ru & Shan Zhong(32463)
A novel NDIPTA organic heterojunction photocatalyst with built-in electric field for efficient hydrogen production by Jiahui Yang & Baojun Ma & Yongfa Zhu(32437)
Enhanced conversion of methane to liquid-phase oxygenates via hollow ferrite nanotube@horseradish peroxidase based photoenzymatic catalysis by Jun Duan & Shiying Fan & Xinyong Li & Shaomin Liu(32401)
Ordered macroporous superstructure of defective carbon adorned with tiny cobalt sulfide for selective electrocatalytic hydrogenation of cinnamaldehyde by Xiao-Shi Yuan & Sheng-Hua Zhou & San-Mei Wang & Wenbo Wei & Xiaofang Li & Xin-Tao Wu & Qi-Long Zhu(32330)
What's Done in Darkness by Kayla Perrin(27245)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26627)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26552)