Skip to content

Commit

Permalink
renaming service-registration to zookeeper, ServiceRegistration to Zo…
Browse files Browse the repository at this point in the history
…oKeeper, fixing the deps
  • Loading branch information
arun-gupta committed Jun 12, 2015
1 parent d453903 commit c8a4c37
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion microservice/catalog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.javaee7.wildfly.samples.services.Services;
import org.javaee7.wildfly.samples.zookeeper.ZooKeeper;

/**
* @author arungupta
*/
@Startup
@Singleton
public class CatalogService {
Services service;
ZooKeeper zk;

@PostConstruct
public void registerService() {
service = Services.getInstance("192.168.99.103", 2181);
service.registerService("catalog", "http://localhost:8080/catalog/resources/catalog");
zk = ZooKeeper.getInstance("192.168.99.103", 2181);
zk.registerService("catalog", "http://localhost:8080/catalog/resources/catalog");
}

@PreDestroy
public void stopService() {
service.registerService("catalog", "http://localhost:8080/catalog/resources/catalog");
public void unregisterService() {
zk.unregisterService("catalog", "http://localhost:8080/catalog/resources/catalog");
}
}
2 changes: 1 addition & 1 deletion microservice/everest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import org.javaee7.wildfly.samples.services.Services;
import org.javaee7.wildfly.samples.zookeeper.ZooKeeper;

/**
* @author arungupta
*/
@ApplicationScoped
public class ServiceDiscoveryZooKeeper implements ServiceDiscoveryURI {

Services service;
ZooKeeper zk;

@PostConstruct
public void init() {
service = Services.getInstance("192.168.99.103", 2181);
zk = ZooKeeper.getInstance("192.168.99.103", 2181);
}

@Override
public String getUserServiceURI() {
return service.discoverService("user");
return zk.discoverService("user");
}

@Override
public String getCatalogServiceURI() {
return service.discoverService("catalog");
return zk.discoverService("catalog");
}

@Override
public String getOrderServiceURI() {
return service.discoverService("order");
return zk.discoverService("order");
}
}
2 changes: 1 addition & 1 deletion microservice/order/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.javaee7.wildfly.samples.services.Services;
import org.javaee7.wildfly.samples.zookeeper.ZooKeeper;

/**
* @author arungupta
*/
@Startup
@Singleton
public class OrderService {
Services service;
ZooKeeper zk;

@PostConstruct
public void registerService() {
service = Services.getInstance("192.168.99.103", 2181);
service.registerService("order", "http://localhost:8080/order/resources/order");
zk = ZooKeeper.getInstance("192.168.99.103", 2181);
zk.registerService("order", "http://localhost:8080/order/resources/order");
}

@PreDestroy
public void stopService() {
service.unregisterService("order", "http://localhost:8080/order/resources/order");
zk.unregisterService("order", "http://localhost:8080/order/resources/order");
}
}
4 changes: 2 additions & 2 deletions microservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<module>user</module>
<module>order</module>
<module>everest</module>
<module>services</module>
<module>zookeeper</module>
</modules>

<name>Shopping Cart Microservice</name>
Expand All @@ -30,7 +30,7 @@
<dependencies>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion microservice/user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.javaee7.wildfly.samples</groupId>
<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.javaee7.wildfly.samples.services.Services;
import org.javaee7.wildfly.samples.zookeeper.ZooKeeper;

/**
* @author arungupta
*/
@Startup
@Singleton
public class UserService {
Services service;
ZooKeeper zk;

@PostConstruct
public void registerService() {
service = Services.getInstance("192.168.99.103", 2181);
service.registerService("user", "http://localhost:8080/user/resources/user");
zk = ZooKeeper.getInstance("192.168.99.103", 2181);
zk.registerService("user", "http://localhost:8080/user/resources/user");
}

@PreDestroy
public void stopService() {
service.unregisterService("user", "http://localhost:8080/user/resources/user");
zk.unregisterService("user", "http://localhost:8080/user/resources/user");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>services</artifactId>
<artifactId>zookeeper</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
</dependencies>
<name>services</name>
<name>zookeeper</name>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.javaee7.wildfly.samples.services;
package org.javaee7.wildfly.samples.zookeeper;

import java.util.List;
import org.apache.curator.framework.CuratorFramework;
Expand All @@ -10,24 +10,24 @@
/**
* @author arungupta
*/
public class Services {
public class ZooKeeper {

private static Services INSTANCE;
private static String zkHost;
private static int zkPort;
private static ZooKeeper INSTANCE;
private static String host;
private static int port;

public static final Services getInstance(String zkHost, int zkPort) {
public static final ZooKeeper getInstance(String host, int port) {
if (null == INSTANCE) {
INSTANCE = new Services();
Services.zkHost = zkHost;
Services.zkPort = zkPort;
INSTANCE = new ZooKeeper();
ZooKeeper.host = host;
ZooKeeper.port = port;
}
return INSTANCE;
}

public void registerService(String name, String uri) {
try {
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkHost + ":" + zkPort, new RetryNTimes(5, 1000));
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(host + ":" + port, new RetryNTimes(5, 1000));
curatorFramework.start();
String znode = "/services/" + name;

Expand Down Expand Up @@ -61,7 +61,7 @@ public void unregisterService(String name, String uri) {

public String discoverService(String name) {
try {
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkHost + ":" + zkPort, new RetryNTimes(5, 1000));
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(host + ":" + port, new RetryNTimes(5, 1000));
curatorFramework.start();
String znode = "/services/" + name;

Expand Down

0 comments on commit c8a4c37

Please sign in to comment.