Author: ilya_shaikovsky
Date: 2011-01-25 13:11:23 -0500 (Tue, 25 Jan 2011)
New Revision: 21223
Modified:
sandbox/trunk/examples/irc-client/src/main/java/org/ircclient/controller/ChatBean.java
Log:
Modified:
sandbox/trunk/examples/irc-client/src/main/java/org/ircclient/controller/ChatBean.java
===================================================================
---
sandbox/trunk/examples/irc-client/src/main/java/org/ircclient/controller/ChatBean.java 2011-01-25
17:12:42 UTC (rev 21222)
+++
sandbox/trunk/examples/irc-client/src/main/java/org/ircclient/controller/ChatBean.java 2011-01-25
18:11:23 UTC (rev 21223)
@@ -29,18 +29,13 @@
private static final String SERVER_URL = "irc.freenode.org";
private static final int SERVER_PORT = 6667;
private static final String CHANNEL_PREFIX = "#";
- private static final String DEFAULT_CHANNEL = "richfaces";
+ private static final String DEFAULT_CHANNEL = "richfaces_push";
private static final Logger LOGGER = LogFactory.getLogger(ChatBean.class);
private String channelName;
private String message;
private transient TopicsContext topicsContext;
- public ChatBean() {
- LOGGER.info("TOPICS CONTEXT INITIALIZED");
- topicsContext = TopicsContext.lookup();
- }
-
public void connect() {
try {
this.connect(SERVER_URL, SERVER_PORT);
@@ -69,11 +64,18 @@
this.disconnect();
}
+ private TopicsContext getTopicsContext() {
+ if (topicsContext == null){
+ topicsContext = TopicsContext.lookup();
+ }
+ return topicsContext;
+ }
+
@Override
protected void onMessage(String channel, String sender, String login, String
hostname, String message) {
String channelName = channel.replace(CHANNEL_PREFIX, "");
try {
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}: {2}", new Date(),
sender, message));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
@@ -83,7 +85,7 @@
@Override
protected void onUserList(String channel, User[] users) {
try {
- topicsContext.publish(new TopicKey("chat", channelName +
"List"), null);
+ getTopicsContext().publish(new TopicKey("chat", channelName +
"List"), null);
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
}
@@ -92,8 +94,8 @@
@Override
protected void onJoin(String channel, String sender, String login, String hostname)
{
try {
- topicsContext.publish(new TopicKey("chat", channelName +
"List"), null);
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName +
"List"), null);
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}: {2}", new Date(),
sender, "joined channel"));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
@@ -103,8 +105,8 @@
@Override
protected void onPart(String channel, String sender, String login, String hostname)
{
try {
- topicsContext.publish(new TopicKey("chat", channelName +
"List"), null);
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName +
"List"), null);
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}: {2}", new Date(),
sender, "left channel"));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
@@ -114,8 +116,8 @@
@Override
protected void onNickChange(String oldNick, String login, String hostname, String
newNick) {
try {
- topicsContext.publish(new TopicKey("chat", channelName +
"List"), null);
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName +
"List"), null);
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}", new Date(), oldNick
+ " changed nick to " + newNick));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
@@ -125,8 +127,8 @@
@Override
protected void onQuit(String sourceNick, String sourceLogin, String sourceHostname,
String reason) {
try {
- topicsContext.publish(new TopicKey("chat", channelName +
"List"), null);
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName +
"List"), null);
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}: {2} {3}", new
Date(), sourceNick, "joined channel", reason));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);
@@ -140,7 +142,7 @@
public void send() {
this.sendMessage(CHANNEL_PREFIX + channelName, message);
try {
- topicsContext.publish(new TopicKey("chat", channelName),
+ getTopicsContext().publish(new TopicKey("chat", channelName),
MessageFormat.format("{0,time,medium} {1}: {2}", new Date(),
this.getName(), message));
} catch (MessageException e) {
LOGGER.error(e.getMessage(), e);