Skip to content

Commit

Permalink
WIP EJB remote client
Browse files Browse the repository at this point in the history
  • Loading branch information
rhusar committed Nov 22, 2013
1 parent f30b0c1 commit 795fbf7
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import java.io.InputStreamReader;
import java.util.Properties;

/**
* @author Ondrej Chaloupka
*/

public class StatefulRemoteClient {

public static void main(String[] args) throws Exception {
Expand All @@ -43,40 +41,8 @@ public static void main(String[] args) throws Exception {
String input = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Thread.sleep(500); // wait for cluster is prepared
System.out.println("To exit enter 'q', to print list of strings 'print', to add string to list on server 'add':");
System.out.print("$ ");
input = br.readLine().trim();

while (!"q".equals(input) && !"quit".equals(input)) {

// printing strings from server
if(input.startsWith("print")) {
System.out.println("Printing strings from server");
int number = 1;
for(String str: statefulBean.getStrings()) {
System.out.println(String.format("String %d: %s", number, str));
number++;
}
}

// adding strings to server
if(input.startsWith("add")) {
String[] splittedString = input.split(" ", 2);
String stringToAdd;
if(splittedString.length <= 1) {
System.out.print("Get me string to add: ");
stringToAdd = br.readLine();
} else {
stringToAdd = splittedString[1];
}
statefulBean.addString(stringToAdd);
System.out.println("String '" + stringToAdd + "' was send to server.");
}

System.out.print("$ ");
input = br.readLine().trim();
}
// TODO: implement sending string to server and lookuping the list of them
// TODO: watch how the cluster behaves when one of the nodes goes down
}

/**
Expand All @@ -86,12 +52,10 @@ public static void main(String[] args) throws Exception {
*/
private static StatefulRemote lookupStatefulRemote() throws NamingException {
final Properties jndiProperties = new Properties();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
// TODO: set up properties
final Context ctx = new InitialContext(jndiProperties);

return (StatefulRemote) ctx
.lookup("ejb:/lesson6-server-side-1.0.0-SNAPSHOT//StatefulBean!" + StatefulRemote.class.getName() + "?stateful");
// TODO: jndi lookup for stateful bean
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@

package cz.muni.fi.pv243.lesson6.ejb.remote.client;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import cz.muni.fi.pv243.lesson06.ejb.remote.stateless.StatelessRemote;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
* @author Ondrej Chaloupka
*/

public class StatelessRemoteClient {

public static void main(String[] args) throws Exception {
Expand All @@ -58,12 +52,7 @@ public static void main(String[] args) throws Exception {

while (!"q".equals(input.trim())) {

for (int i = 0; i < interations; i++) {
String nodeName = statelessBean.getNodeName();
Integer calls = numberOfCalls.get(nodeName);
numberOfCalls.put(nodeName, calls == null ? 1 : ++calls);
Thread.sleep(5);
}
// TODO: call stateless bean method and watch the load balancing

printingSemaphore.acquire();
System.out.print("To exit enter 'q', to continue hit ENTER: ");
Expand All @@ -83,13 +72,9 @@ public static void main(String[] args) throws Exception {
*/
private static StatelessRemote lookupStatelessRemote()
throws NamingException {
final Properties jndiProperties = new Properties();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
final Context ctx = new InitialContext(jndiProperties);
// TODO: setup properties

return (StatelessRemote) ctx
.lookup("ejb:/lesson6-server-side-1.0.0-SNAPSHOT//StatelessBean!" + StatelessRemote.class.getName());
// TODO: jndi lookup for stateless bean
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,5 @@

package cz.muni.fi.pv243.lesson06.ejb.remote.stateful;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateful;

import org.jboss.ejb3.annotation.Clustered;


/**
* @author Ondrej Chaloupka
*/
@Clustered
@Stateful
public class StatefulBean implements StatefulRemote {

private final List<String> stringList = new ArrayList<String>();

@Override
public void addString(String str) {
stringList.add(str);
}

@Override
public List<String> getStrings() {
return stringList;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

import java.util.List;

import javax.ejb.Remote;

/**
* @author Ondrej Chaloupka
*/
@Remote
public interface StatefulRemote {
/**
* Adding string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,5 @@

package cz.muni.fi.pv243.lesson06.ejb.remote.stateless;

import javax.ejb.Stateless;

import org.jboss.ejb3.annotation.Clustered;

import cz.muni.fi.pv243.lesson06.ejb.remote.util.NodeNameGetter;

/**
* @author Ondrej Chaloupka
*/
@Clustered
@Stateless
public class StatelessBean implements StatelessRemote {

@Override
public String getNodeName() {
return NodeNameGetter.getNodeName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@

package cz.muni.fi.pv243.lesson06.ejb.remote.stateless;

import javax.ejb.Remote;

/**
* @author Ondrej Chaloupka
*/
@Remote
public interface StatelessRemote {
/**
* @return name of node where this method is called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

package cz.muni.fi.pv243.lesson06.ejb.remote.util;

/**
* @author Ondrej Chaloupka
*/
public class NodeNameGetter {

private NodeNameGetter() {
Expand All @@ -34,7 +31,6 @@ private NodeNameGetter() {
* Returns name of the node where this is called.
*/
public static String getNodeName() {
String nodename = System.getProperty("jboss.node.name");
return nodename;
// TODO: Get property "jboss.node.name"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 795fbf7

Please sign in to comment.