Menu

CVS Version 1.3.20110802

Developers
Rene
2011-08-03
2013-04-22
  • Rene

    Rene - 2011-08-03

    Seit dieser Version is es möglich über extern liegende jar Files  eigenständige Threads nachzuladen und zu starten
    Das jar File mus nur den Namen threadmanager.jar haben und im lib Ordner gespeichert sein
    Der Aufbau im File sollte src.freecs.threadmanger sein und das Interface IThreadMangerPlugin implenmendiert haben

    Der Chat erledigt den Start dann von selber
    Auf Onlinetalk wird der HighscoreManager so gestartet der 1 mal pro Woche aktiv wird und Punkte vergibt

    Gruß Rene

     
  • Rene

    Rene - 2012-06-23

    Ein Beispiel

    package freecs.threadmanager;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.Properties;
    import java.util.Vector;

    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;

    import org.xml.sax.Attributes;
    import org.xml.sax.helpers.DefaultHandler;

    import freecs.Server;

    import freecs.auth.SQLAuthenticator;
    import freecs.auth.sqlConnectionPool.DbProperties;
    import freecs.core.MessageParser;
    import freecs.core.User;
    import freecs.core.UserManager;
    import freecs.interfaces.IThreadManagerPlugin;
    import freecs.layout.TemplateSet;

    import freecs.util.EntityDecoder;

    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.io.Reader;
    import java.io.Writer;
    import java.net.HttpURLConnection;
    import java.net.ProtocolException;

    public class HighscoreManager extends Thread implements IThreadManagerPlugin{
        public static final HighscoreManager mgr = new HighscoreManager ();
        public static HighscoreManager instance = new HighscoreManager();
       
        private long SLEEP_TIME = 60000; // ms
        private volatile boolean isRunning = true;
       
        private int checkedHour = -1;
        private int checkedDay = -1;
       // private int checkedMinute = -1;
        private int counter = 0;
        private int checkedWeekDay = -1;
        private static Vector<String> winUsers = new Vector<String>();
       
        @Override
        public IThreadManagerPlugin instanceForSystem() throws Exception {
            // TODO Auto-generated method stub
            return this;
        }
    public static Object getMasterInstance (){
    return mgr;
    }
        /**
         * @param args
         * @throws Exception
         */
        public static void main(String args) throws Exception {
            // TODO Auto-generated method stub
            checkHighscore();
        }
       
        public void startManager(){
            if (!mgr.isAlive()) {
                if (Server.DEBUG ) {
                    Server.log("", "HighscoreManager run: ", Server.MSG_STATE, Server.LVL_MAJOR);
                }
                mgr.setName("HighscoreManager");
                mgr.setPriority(Thread.MIN_PRIORITY);
                mgr.startHighscore();
            }
        }
       
        public void stopManager(){
            if (mgr.isAlive()) {
            startShutdown();
                Server.log("", "HighscoreManager stopping ", Server.MSG_STATE, Server.LVL_MAJOR);
                mgr.close();
            }
        }
       
        public HighscoreManager(){
           
        }
       
        private void startHighscore(){
            this.start();
           
            Runtime.getRuntime().addShutdownHook(new Thread(){
               
                public void run(){
                    stopManager();
                }
            }
            );
        }
       
        public void run(){
            while(!isInterrupted() && isRunnig()){        
                    try {
                        sleep(SLEEP_TIME);
                      
    ………
                                    }
                                }
                            }                  
                    }
                
                    catch(InterruptedException e){
                        Server.log(this, "HighscoreManager InterruptedException: "+e, Server.MSG_STATE, Server.LVL_MAJOR);
                        break;
                    } catch(Exception e){
                        Server.log(this, "HighscoreManager Exception: "+e, Server.MSG_ERROR, Server.LVL_MAJOR);
                        break;
                    }
                }       
        }
       
        private boolean isRunnig(){
        return isRunning;
        }
       
        private void startShutdown(){
        isRunning=false;
        }

     

Log in to post a comment.