Commit 026af0e3 by Tuomas Riihimäki

IRC bot beans, topic, ym initial stuff

1 parent 1a6f11c0
package fi.codecrew.moya.beans;
import javax.ejb.Local;
import fi.iudex.utils.irc.IrcBot;
@Local
public interface BotBeanLocal {
void add(IrcBot bot);
}
package fi.codecrew.moya.beans;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Stateless;
import fi.iudex.utils.irc.IrcBot;
/**
* Session Bean implementation class BotBean
*/
@Singleton
@LocalBean
public class BotBean implements BotBeanLocal {
private IrcBot bot;
/**
* Default constructor.
*/
public BotBean() {
// TODO Auto-generated constructor stub
}
@Override
public void add(IrcBot bot) {
this.setBot(bot);
}
public IrcBot getBot() {
return bot;
}
public void setBot(IrcBot bot) {
this.bot = bot;
}
}
package fi.codecrew.moya.beans;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Message-Driven Bean implementation class for: IrcBotTopicListener
*/
@MessageDriven(mappedName = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC)
public class IrcBotMoyaEventTopicListener implements MessageListener {
private static final Logger logger = LoggerFactory.getLogger(IrcBotMoyaEventTopicListener.class);
@EJB
private BotBean botbean;
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
TextMessage tm = (TextMessage) message;
try {
botbean.getBot().say("Got msg: " + tm.getText());
logger.info("Received moya event message for irc bot {}", message);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package fi.codecrew.moya.beans;
import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import javax.management.MBeanServerConnection;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
@Startup
public class JmxNotificationTestBean implements NotificationListener {
@PostConstruct
public void startup() {
// JMXConnector jcf;
// try {
// jcf = JMXConnectorFactory.connect(new JMXServiceURL(null, null, 8686));
// MBeanServerConnection mbsc = jcf.getMBeanServerConnection();
// } catch (IOException e) {
// logger.warn("Error creating jmx connection", e);
// }
}
private static final Logger logger = LoggerFactory.getLogger(JmxNotificationTestBean.class);
@Override
public void handleNotification(Notification notification, Object handback) {
logger.info("Handling jmx Notification, src: {}, type {}, userdata: {}", new Object[] { notification.getSource(), notification.getType(), notification.getUserData() });
}
}
package fi.codecrew.moya.beans;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jms.JMSConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSDestinationDefinition;
import javax.jms.Topic;
@Stateless
@JMSDestinationDefinition(name = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC,
destinationName = MoyaEventSender.MOYA_EVENT_TOPIC_DESTINATION,
description = "Events generated by moya to be logged or otherwise handler",
interfaceName = "javax.jms.Topic")
public class MoyaEventSender {
static final String MOYA_EVENT_TOPIC_DESTINATION = "moyaEventTopic";
public static final String MOYA_EVENT_SENDER_TOPIC = "java:global/jms/moyaEventTopic";
@Inject
JMSContext context;
@Resource(mappedName = MOYA_EVENT_SENDER_TOPIC)
Topic topic;
public void sendMessage(String message) {
context.createProducer().send(topic, message);
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import java.util.Calendar;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.transaction.UserTransaction;
import org.slf4j.Logger;
import fi.codecrew.moya.facade.LogEntryFacade;
import fi.codecrew.moya.facade.LogEntryTypeFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.SecurityLogType;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.LogEntryType;
import fi.codecrew.moya.model.User;
/**
* Session Bean implementation class SercurityBean
*/
@MessageDriven(mappedName = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC)
public class MoyaEventTopicLoggingBean implements LoggingBeanLocal {
private static final boolean DEBUG = true;
private final Logger logger = org.slf4j.LoggerFactory
.getLogger(MoyaEventTopicLoggingBean.class);
// @EJB
// private LogEntryTypeFacade typeFacade;
// @EJB
// private LogEntryFacade entryFacade;
@EJB
private EventBeanLocal eventbean;
// @Resource
// UserTransaction utx;
// @Override
// public LogEntry logPermissionDenied(User user, Exception exception) {
// LogEntry entry = null;
//
// entry = logMessage(SecurityLogType.permissionDenied, user,
// exception.getMessage());
// logger.debug(entry.toString(), exception);
//
// return entry;
//
// }
//
// public LogEntry logException(User user, Exception exception) {
//
// LogEntry entry = logMessage(SecurityLogType.unknownException, user,
// exception.getMessage());
// logger.debug(entry.toString(), exception);
// return entry;
// }
//
// public LogEntry logMessage(User user, String... description) {
//
// LogEntry entry = logMessage(SecurityLogType.genericMessage, user,
// toString(description));
//
// return entry;
// }
//
// private static final String toString(String... desc) {
// StringBuilder msg = new StringBuilder();
// for (String msgpart : desc) {
// msg.append(msgpart);
// }
// return msg.toString();
// }
//
// public LogEntry logMessage(String... description) {
// LogEntry entry = logMessage(SecurityLogType.genericMessage,
// toString(description));
// return entry;
//
// }
// public LogEntry logPermissionDenied(User currentuser, String... message)
// {
// return logMessage(SecurityLogType.permissionDenied, currentuser,
// toString(message));
// }
@Override
public LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user,
Object... description) {
LogEntry entry = null;
if (event == null) {
event = eventbean.getCurrentEvent();
}
try {
String desc = toString(description);
logger.warn("Sending logmsg {}", desc);
//LogEntryType type = typeFacade.findOrCreate(paramType);
// entry = new LogEntry(Calendar.getInstance());
// entry.setParentEvent(event);
// entry.setType(type);
// entry.setDescription(desc);
// entry.setUser(user);
// entryFacade.create(entry);
String msg = "SECURITY DEBUG: Type: \"" + paramType.name() +
"\" user \"" + paramType.name() +
"\", description \"" + ((user == null) ? "null" : user.getLogin()) + "\"" + desc;
sender.sendMessage(msg);
// utx.commit();
} catch (Exception e) {
logger.warn("Exception at SecurityBean", e);
}
return entry;
}
@Override
public LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description) {
LanEvent event = null;
User usr = null;
if (user != null)
{
event = user.getEvent();
usr = user.getUser();
}
return logMessage(paramType, event, usr, description);
}
private static final String toString(Object... desc) {
StringBuilder msg = new StringBuilder();
for (Object msgpart : desc) {
msg.append(msgpart);
}
return msg.toString();
}
}
...@@ -63,7 +63,11 @@ ...@@ -63,7 +63,11 @@
<version>${javaee-api-version}</version> <version>${javaee-api-version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>fi.iudex</groupId>
<artifactId>utils-standalone</artifactId>
<version>1.0.8</version>
</dependency>
<dependency> <dependency>
<groupId>net.sf.barcode4j</groupId> <groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId> <artifactId>barcode4j</artifactId>
...@@ -110,6 +114,10 @@ ...@@ -110,6 +114,10 @@
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.1.2</version> <version>1.1.2</version>
<dependency>
<groupId>fi.iudex</groupId>
<artifactId>jerklib</artifactId>
<version>1.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.matlux</groupId> <groupId>net.matlux</groupId>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!