There are many confusion about zookeeper,what zookeeper is ?.
What is the role of zookeeper .What zookeeper does.
In Simple term,Zookeeper ensure people or node which are agreed to work together ,should work together.
Read Preference Mode
|
Description
|
In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.
| |
Operations read from member of the replica set with the least network latency, irrespective of the member’s type.
|
// function somewhere in father-controller.js var makePromiseWithSon = function() { // This service's function returns a promise, but we'll deal with that shortly SonService.getWeather() // then() called when son gets back .then(function(data) { // promise fulfilled if (data.forecast==='good') { prepareFishingTrip(); } else { prepareSundayRoastDinner(); } }, function(error) { // promise rejected, could log the error with: console.log('error', error); prepareSundayRoastDinner(); }); };
app.factory('SonService', function ($http, $q) { return { getWeather: function() { // the $http API is based on the deferred/promise APIs exposed by the $q service // so it returns a promise for us by default return $http.get('http://fishing-weather-api.com/sunday/afternoon') .then(function(response) { if (typeof response.data === 'object') { return response.data; } else { // invalid response return $q.reject(response.data); } }, function(response) { // something went wrong return $q.reject(response.data); }); } }; });
public class Singleton {
private Prototype prototype;
public Singleton(Prototype prototype) {
this.prototype = prototype;
}
public void doSomething() {
prototype.foo();
}
public void doSomethingElse() {
prototype.bar();
}
}
public abstract class Singleton {
protected abstract Prototype createPrototype();
public void doSomething() {
createPrototype().foo();
}
public void doSomethingElse() {
createPrototype().bar();
}
}
<bean id="prototype" class="ch.frankel.blog.Prototype" scope="prototype" />
<bean id="singleton" class="sample.MySingleton">
<lookup-method name="createPrototype" bean="prototype" />
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="a" class="com.pkg.Singleton" scope="singleton" />
</beans>
Bean Singleton public class Singleton{
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
Test public class Test {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");
Singleton a1 = ctx.getBean("a", Singleton.class);
a1.setText("text A1");
Singleton a2 = ctx.getBean("a", Singleton.class);
a2.setText("text A2");
System.out.println("a1: " + a1.getText());
System.out.println("a2: " + a2.getText());
}
}
Output: a1: text A2
a2: text A2
And now let's create another one ApplicationContext: public class Test {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");
ApplicationContext ctx2 = new ClassPathXmlApplicationContext("spring-config.xml");
Singleton a1 = ctx.getBean("a", Singleton.class);
a1.setText("text A1");
Singleton a2 = ctx2.getBean("a", Singleton.class);
a2.setText("text A2");
System.out.println("a1: " + a1.getText());
System.out.println("a2: " + a2.getText());
// both ctx and ctx2 have same classloaders
System.out.println("context1 classloader: " + ctx.getClassLoader());
System.out.println("context2 classloader: " + ctx2.getClassLoader());
}
}
Output: a1: text A1
a2: text A2
context1 classloader: sun.misc.Launcher$AppClassLoader@5284e9
context2 classloader: sun.misc.Launcher$AppClassLoader@5284e9