Horizontal Clustering using HazelCast - java

I am using hazelCast-3.0 jars . I am able to create vertical cluster(on the same System where only port no. differ from one server to other Ip remains the same.) and its working pretty good.But i want to create horizontal cluster(where i can use any ip address along with any port no. depending on the configuration). If this is possible in hazelCast then please share how. i went through several links like http://www.hazelcast.com/docs/1.9.4/manual/multi_html/ch11.html
if this link is useful the suggest me how. I made only change to hazelcast.xml.
<tcp-ip enabled="true">
<hostname>172.22.65.111</hostname>
<hostname>172.22.68.19</hostname>
<interface>172.22.*.*</interface>
</tcp-ip>
On both the system same jar file are being used.It i create a map name "xyz" and store some value to it .Then it should be available to other system with same map name "xyz".
here is the code that I am using on my system
clientConfig.addAddress("172.22.65.111:5701");
System.out.println("p2");
HazelcastInstance client = HazelcastClient
.newHazelcastClient(clientConfig);
IMap<Integer, String> map = client.getMap("m");
map.put(1,"ram");
Same code is on the second system also except ip and port. And insteed of put i am trying to get on the other system.

your link refers to an outdated Version of the Manual.
If you follow the getting started guide at
http://www.hazelcast.com/docs/3.0/manual/single_html/#GettingStarted
you should be able to form a horizontal cluster by starting the sample code on two separate machines.
The current hazelcast distribution also contains a bin folder with sample applications.

I find a new in memory grid based on hazelcast 3.0 clone-griddatamaster.(griddatamaster.wordpress.com) They claim they will provide enterprise class future like security,management console...and some cool futures from gigaspace and oracle coherence
griddatamaster.wordpress.com

Related

Ways to Implement Tomcat Server-Wide Persistent and Changeable Variables Across All WebApps

Production Environment: Tomcat 9 on CentOS 7 x64, mysql/mariadb 5.5x
Testing Environment: Tomcat 9 in Eclipse on Windows 7 x64, mysql 5.5x
I'm a Tomcat newbie looking for the best method to have server-wide variables readable/writable from all Webapps for things like MaintenanceMode(on/off) and MaintenanceMessage, etc.
These are the variable properties I'm looking for:
Readable/writable from all instances of all java servlets on all webapps.
Value persists after OS, Tomcat, or Webapp restart.
I must be able to change the value of it from one webapp and then all other webapps recognize the change quickly, ideally without restarting.
Ideally I wouldn't want to read the variable from disk on each server request. In case server is getting DDOSed or something.
Ideally the solution is OS independent.
If it's a disk file solution please recommend a place for me to store the file.
I'm new to Tomcat so some detail in any answers would be appreciated or links to detail. I'll probably be using a servlet on it's own 'admin' webapp that's only accessible through SSH-tunneling, etc, to set the variables. Then the public webapps would respond to any changes, like showing a maintenance message while I backup databases. I could also possibly change the variables using linux commands if needed.
If I stored the server variables in a database that could be fine but I wouldn't want to read the DB on every single request most likely, and when I change a variable I'd have to once again notify every webapp/servlet that something was changed and to re-read the DB.
Thanks for any help.
I implemented this recently in the form of "system messages", some of which are for maintenance. But the effect is the same. We had some additional "requirements" which helped us form the solution. These may or may not match up to your expectations/desires:
Multiple-server coordination
Immediate synchronization was not necessary
We used our relational database for the actual data storage. A single table with "system messages" and a few other fields such as when the messages became effective (not_before DATETIME) and when the messages became ineffective (not_after DATETIME).
On startup, the application reads the system messages table to find the currently-valid messages and stores them in application scope, including their validity dates. Whenever we want to show them on the screen, we check each item in memory and evict any that have expired. This is pretty fast.
Every X minutes (e.g. from cron), we make a request to a special servlet (on each server) that re-loads the system messages from the database. We protect that servlet by only allowing requests from certain IPs, so DOS is not an issue.
Not only can we add a system message from any server in the cluster, but we can also add one by writing directly to the database. That may be advantageous if you don't always want to use your application to generate these events.
You can change the value for X to anything as low as 1 (minute) if you are using cron. If you use some other kind of system, you can probably get updated even more often. I would seriously reconsider your requirement of "immediate" recognition because that requires a system that has much worse performance.
If you can guarantee that only your application can generate these changes, and you have a list of all other servers in the cluster somewhere, you could theoretically ping them all with the new message (or notify them that a new message exists and it's time to update their message-list), but that kind of thing is better-done with an orchestration tool such as Kubernetes, and we are getting a little out of scope IMO.

Checking if application is already running

I have a Java Application that uses JPA on a file DB.
I want only one instance of my application running (Note that the DB gets locked to the first instance of the application).
How could I check if my DB is locked or not, and present a message to the user?
Telnet your DB with its ip and the port number.
Eclipse solve this solution with a .lock file. Other solution can be: try to use a port: bind to port 12345. If you can than you are the only one king of the hill if you can't, than maybe other are using that hill. Any other apps can.
The .lock file has many disadvantages too.
And the last and best solution is: do it with platform dependent at way at OS level via JNI, but require a lot of work and has disadvantages too.

Retrieving port number in-application using Play Framework

I have two Play framework web applications running on my system on ports 9001 and 9002. I was wondering if there was any way I could retrieve which port they were running on from within my Java code.
Is this possible?
Yes. You can get the port like this:
int port = Integer.parseInt(Play.configuration.getProperty("http.port", 9000));
Of course, you have to import the class play.Play.
In Play 2.4.x:
Play.application().configuration().getString("http.port");
or simply:
System.getProperty("http.port");
This only works in production mode, when the http.port is set via the Java -D parameter.
Since the system does not let me comment yet, I'm forced to add my comment here.
The given answer by Carsten must be for play1, for play2 see Retrieving port number in Play Framework 2 app

How to create Agent and migrate it to Remot host?

I am looking to create Multi-agent systems based focused crawling. I have seen different mobile framworks such as Aglet, JADE, etc,. My work is want to create a number of agent at resident Local host and want to move it with parameter to resident Remote host. My question are, which framwork should I used to create agent? and how to create agent and migrate it to remote host via middle agent. please give me some example code how to create agent and migrate it. Thank you.
Take a look at Mobility-RPC, there are examples to do this on the front page.

How to access an application using different host and port with JBoss 5

I have deployed my application in Jboss and I want to give users access to my application with different host and ports per user. To explain clearly:
http://192.168.11.21/MBeanProject/servcount
for user1 and
http://192.168.11.22/MBeanProject/servcount
for user2 so on...
How could I do this? I am using JBoss5 as my AS. Based on the user request I need to count the number of times that user1 accessed the first url and the number of times the user2 accessed the second one ...and so on... Can you guide me how could I procced? Currently I am working with the Snmp traps using JBoss5
You will need a separate IP address for every user, right? Which doesn't sound like a very scalable solution, but if you do decide to do this you will then need as many IP addresses as you have users, and tell JBoss to listen to all interfaces using a startup argument like bin/run.sh -b 0.0.0.0. Then, your Servlets will be able to tell the full IP address by checking (eg) HttpServletRequest#getRequestUrl(). Or, you could have a separate instance of JBoss running for each user, binding each one to a different IP.
However, this is a very unusual design. It offers poor scalability, difficult maintenance, difficult network config and sysadmin tasks, and confusion for any new devs on the project. Appservers are designed to be able to serve multiple users on the same instance. I can't really see any positives to a design like this. Unless you have very good reasons for doing so (in which case please share!) you should probably use different URLs for different users, like:
http://192.168.11.21/MBeanProject/user1/servcount
http://192.168.11.21/MBeanProject/user2/servcount
or
http://192.168.11.21/MBeanProject/servcount?user=user1
http://192.168.11.21/MBeanProject/servcount?user=user2

Categories