Commit 26ead10a authored by Matt Tucker's avatar Matt Tucker Committed by matt

Cleanup thread usage to use TaskEngine.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6207 b35dd754-fafc-0310-a699-88a17e54d16e
parent fffe14e6
......@@ -14,9 +14,6 @@ package org.jivesoftware.util;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ArrayBlockingQueue;
import javax.mail.Address;
import javax.mail.*;
......@@ -79,16 +76,12 @@ public class EmailService {
private boolean sslEnabled;
private boolean debugEnabled;
private ThreadPoolExecutor executor;
private Session session = null;
/**
* Constructs a new EmailService instance.
*/
private EmailService() {
executor = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
host = JiveGlobals.getProperty("mail.smtp.host", "localhost");
port = JiveGlobals.getIntProperty("mail.smtp.port", 25);
username = JiveGlobals.getProperty("mail.smtp.username");
......@@ -137,7 +130,7 @@ public class EmailService {
if (messages.size() == 0) {
return;
}
executor.execute(new EmailTask(messages));
TaskEngine.getInstance().submit(new EmailTask(messages));
}
/**
......@@ -257,8 +250,8 @@ public class EmailService {
* {@link #sendMessages(Collection)} in that messages are sent
* before this method returns rather than queueing the messages to be sent later.
*
* @param messages
* @throws MessagingException
* @param messages the messages to send.
* @throws MessagingException if an error occurs.
*/
public void sendMessagesImmediately(Collection<MimeMessage> messages)
throws MessagingException
......
......@@ -571,9 +571,10 @@ public class XMPPServer {
}
/**
* Restarts the HTTP server only when running in stand alone mode. The restart process will be done
* in another thread that will wait 1 second before doing the actual restart. The delay will give time
* to the page that requested the restart to fully render its content.
* Restarts the HTTP server only when running in stand alone mode. The restart
* process will be done in another thread that will wait 1 second before doing
* the actual restart. The delay will give time to the page that requested the
* restart to fully render its content.
*/
public void restartHTTPServer() {
Thread restartThread = new Thread() {
......
......@@ -115,7 +115,6 @@ public class GroupManager {
// Pre-load shared groups. This will provide a faster response
// time to the first client that logs in.
// TODO: use a task engine instead of creating a thread directly.
Runnable task = new Runnable() {
public void run() {
Collection<Group> groups = getSharedGroups();
......@@ -135,9 +134,7 @@ public class GroupManager {
}
}
};
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
TaskEngine.getInstance().submit(task);
}
/**
......
......@@ -13,15 +13,14 @@ package org.jivesoftware.wildfire.multiplex;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.event.SessionEventListener;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -96,28 +95,22 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
sessionManager = XMPPServer.getInstance().getSessionManager();
// Start thread that will send heartbeats to Connection Managers every 30 seconds
// to keep connections open.
Thread hearbeatThread = new Thread() {
TimerTask heartbeatTask = new TimerTask() {
public void run() {
while (true) {
try {
Thread.sleep(30000);
for (ConnectionMultiplexerSession session : sessionManager
.getConnectionMultiplexerSessions()) {
session.getConnection().deliverRawText(" ");
}
}
catch (InterruptedException e) {
// Do nothing
}
catch(Exception e) {
Log.error(e);
try {
for (ConnectionMultiplexerSession session : sessionManager
.getConnectionMultiplexerSessions())
{
session.getConnection().deliverRawText(" ");
}
}
catch(Exception e) {
Log.error(e);
}
}
};
hearbeatThread.setDaemon(true);
hearbeatThread.setPriority(Thread.NORM_PRIORITY);
hearbeatThread.start();
TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND,
30*JiveConstants.SECOND);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment