Skip to content

Instantly share code, notes, and snippets.

@mdelano
Last active December 19, 2017 21:55
Show Gist options
  • Save mdelano/2fcbde2b8f09d89d860f5ade934e2778 to your computer and use it in GitHub Desktop.
Save mdelano/2fcbde2b8f09d89d860f5ade934e2778 to your computer and use it in GitHub Desktop.
Example singleton pattern with super fake rabbit client
/**
* My super fake rabbit client wrapper
*/
public class MySuperFakeRabbitClientWrapper {
private static Logger logger = LoggerFactory.getLogger(MySuperFakeRabbitClientWrapper.class);
private static ActualRabbitClient actualRabbitClient;
private MySuperFakeRabbitClientWrapper() {
// Pseudotastic
this.actualRabbitClient = new ActualRabbitClient();
//totally fake
this.actualRabbitClient.createNewConnectionPool();
}
public static synchronized MySuperFakeRabbitClientWrapper getInstance() {
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder {
public static final MySuperFakeRabbitClientWrapper INSTANCE = new MySuperFakeRabbitClientWrapper();
}
private static synchronized ActualRabbitClient getRabbitClient() {
return this.actualRabbitClient();
}
private static synchronized killRabbit() {
this.actualRabbitClient.killRabbit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment