issue with timermanager(i think?)

Results 1 to 4 of 4
  1. #1
    Account Upgraded | Title Enabled! super861 is offline
    MemberRank
    Oct 2009 Join Date
    229Posts

    issue with timermanager(i think?)

    okay, so i was working on a fishing system for my maplesolaxia source.
    basicly what ive done is a method that starts a timermanager event in maplecharacter.

    whenever a player sits on a chair and that chair equels the fishing chair while player is in X map, that method gets called. when the player goes off a chair, the method gets called with a false boolean that then should stop the timer event. however i don't think it does. Whenever i drop an item (i suppose a timermanager event gets called to delete the item after X ms) i get an error. Could anyone help me out with where i'm going wrong and how i can fix this? I really want to get this system working, but i keep getting stuck.

    useChairHandler method gets called with boolean true) :
    Code:
    if(c.getPlayer().getMapId() == 970020000 && itemId == 3011000 /*&& !c.getPlayer().isFishing*/){ 
                c.getPlayer().goFish(true);
            }
    cancleChairHandler method gets called again with a false boolean this time:
    Code:
    if (id == -1) {
        c.getPlayer().goFish(false);
    }
    * there is more stuff in there that cancles the chair, but this is the only part that matters for my issue.

    the method i made inside maplecharacter:
    Code:
        public void goFish(boolean fish) {
                          
            TimerManager tMan = TimerManager.getInstance();
            final MapleCharacter chr = this;
            if(fish) {         
                //tMan.start();
                tMan.register(new Runnable() {
                    @Override
    
                    public void run() {                   
                        Fishing.doFishing(chr);
                    }
    
                },5000, 5000 );
            }
            else {
                tMan.stop();
            }
        }
    the error im getting after dropping an item:
    Code:
    Error for player ; Destiny on map ; 970020000 - account ; super861
    All: 47 00 6F 9A 4B 44 04 07 00 00 00 01 00
    Now: kevintjuh93 pwns
    java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@292ea3d5 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@35060a12[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
    	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.reject(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(Unknown Source)
    	at server.TimerManager.schedule(TimerManager.java:95)
    	at server.maps.MapleMap.spawnItemDrop(MapleMap.java:1226)
    	at server.MapleInventoryManipulator.drop(MapleInventoryManipulator.java:519)
    	at net.server.channel.handlers.ItemMoveHandler.handlePacket(ItemMoveHandler.java:51)
    	at net.MapleServerHandler.messageReceived(MapleServerHandler.java:134)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
    	at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutputImpl.flush(ProtocolCodecFilter.java:407)
    	at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:236)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
    	at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
    	at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:410)
    	at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:710)
    	at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:664)
    	at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:653)
    	at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67)
    	at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1124)
    	at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    *i didn;t include my fishing java file since that is working fine. If needed i'll post that aswell.


  2. #2
    Valued Member Exonaut is offline
    MemberRank
    Sep 2012 Join Date
    USALocation
    147Posts

    Re: issue with timermanager(i think?)

    You are stopping the TimerManager instead of just stopping your task which will cause the ScheduledThreadPoolExecutor to shutdown and no longer run any tasks that a lot of the other classes in your source use. In this case, spawnItemDrop from MapleMap is trying to schedule the ExpireMapItemJob Runnable but you have shutdown the thread executor so it will throw that exception. Here is how you fix it:

    Place this:
    PHP Code:
    private ScheduledFuture<?fishTask null;
    Anywhere under these:
    PHP Code:
    private ScheduledFuture<?dragonBloodSchedule;
    private 
    ScheduledFuture<?> mapTimeLimitTask = null;
    private ScheduledFuture<?>[] fullnessSchedule = new ScheduledFuture<?>[3];
    private ScheduledFuture<?hpDecreaseTask;
    private 
    ScheduledFuture<?> beholderHealingSchedule, beholderBuffSchedule, BerserkSchedule;
    private ScheduledFuture<?expiretask;
    private 
    ScheduledFuture<?> recoveryTask;
    And change this:
    PHP Code:
    public void goFish(boolean fish) {
                          
            
    TimerManager tMan TimerManager.getInstance();
            final 
    MapleCharacter chr this;
            if(
    fish) {         
                
    //tMan.start();
                
    tMan.register(new Runnable() {
                    @
    Override

                    
    public void run() {                   
                        
    Fishing.doFishing(chr);
                    }

                },
    50005000 );
            }
            else {
                
    tMan.stop();
            }
        } 
    To this:
    PHP Code:
    public void goFish(boolean fish) {
                          
            
    TimerManager tMan TimerManager.getInstance();
            final 
    MapleCharacter chr this;
            if(
    fish) {         
                
    fishTask tMan.register(new Runnable() {
                    @
    Override

                    
    public void run() {                   
                        
    Fishing.doFishing(chr);
                    }

                }, 
    50005000);
            }
            else {
                if (
    fishTask != null) {
                     
    fishTask.cancel(false);
                     
    fishTask null// This is because we do not want a reference to the canceled ScheduledFuture
                                                // And in case this is called twice with false as the argument it will not try to call again.
                
    }
            }
        } 
    And finally find the empty method in MapleCharacter that looks like this:
    PHP Code:
    public final void empty(final boolean remove) {
            if (dragonBloodSchedule != null) {
                dragonBloodSchedule.cancel(false);
            }
            if (hpDecreaseTask != null) {
                hpDecreaseTask.cancel(false);
            }
            if (beholderHealingSchedule != null) {
                beholderHealingSchedule.cancel(false);
            }
            if (beholderBuffSchedule != null) {
                beholderBuffSchedule.cancel(false);
            }
            if (BerserkSchedule != null) {
                BerserkSchedule.cancel(false);
            }
            if (recoveryTask != null) {
                recoveryTask.cancel(false);
            }
            cancelExpirationTask();
            for (ScheduledFuture<?sf timers) {
                
    sf.cancel(false);
            }
            
    timers.clear();
            if (
    maplemount != null) {
                
    maplemount.empty();
                
    maplemount null;
            }
            if (
    remove) {
                
    partyQuest null;
                
    events null;
                
    mpc null;
                
    mgc null;
                
    events null;
                
    party null;
                
    family null;
                
    client null;
                
    map null;
                
    timers null;
            }
        }
    And change it to this:
    PHP Code:
    public final void empty(final boolean remove) {
            if (dragonBloodSchedule != null) {
                dragonBloodSchedule.cancel(false);
            }
            if (hpDecreaseTask != null) {
                hpDecreaseTask.cancel(false);
            }
            if (beholderHealingSchedule != null) {
                beholderHealingSchedule.cancel(false);
            }
            if (beholderBuffSchedule != null) {
                beholderBuffSchedule.cancel(false);
            }
            if (BerserkSchedule != null) {
                BerserkSchedule.cancel(false);
            }
            if (recoveryTask != null) {
                recoveryTask.cancel(false);
            }
                    if (fishTask != null) {
                         fishTask.cancel(false);
                    }
            cancelExpirationTask();
            for (ScheduledFuture<?sf timers) {
                
    sf.cancel(false);
            }
            
    timers.clear();
            if (
    maplemount != null) {
                
    maplemount.empty();
                
    maplemount null;
            }
            if (
    remove) {
                
    partyQuest null;
                
    events null;
                
    mpc null;
                
    mgc null;
                
    events null;
                
    party null;
                
    family null;
                
    client null;
                
    map null;
                
    timers null;
            }
        }

    This last edit is optional but is just "good practice." You can add an isFishing method anywhere in MapleCharacter that looks like this:
    PHP Code:
    public boolean isFishing() {
                     return 
    fishTask != null;
              } 
    And then add it to the CancelChairHandler like this:
    PHP Code:
    if (id == -1) {
                    if (
    c.getPlayer().isFishing()) 
                          
    c.getPlayer().goFish(false);
               } 
    This just saves some negligible overhead from calling the method because we add the null check it does but do not create any other references and simply return a value.
    Last edited by Exonaut; 29-06-17 at 11:11 PM. Reason: syntax highlighting

  3. #3
    Account Upgraded | Title Enabled! super861 is offline
    MemberRank
    Oct 2009 Join Date
    229Posts

    Re: issue with timermanager(i think?)

    @Exonaut , Thanks for the repsonse :) good to know why it didn't work too! I changed the timer event like yo usaid already (took a look in maplemap to see how its handled there and basicly copied that.), but now i know why it should be like this, so that's alwaus good.
    what i did was give the fishing method a boolean parameter, then in the function, if that's true, run the timer event. if its false, it checks if if fishtimerevent!= null, if so cancel the event. if its null, do nothing. your way looks a bit cleaner though. is it roughly the same as just making a boolean in maplecharacter with a getter and setter? or in this case just a setter. If that would be a "cleaner" way to do it, i'll be sure to code that in instead!

    I never knew about the empty function, so i'll be sure to take a look at that when i get back from work.

    thansk alot for taking the time to help :) my fishing system is starting to look better and better :D

  4. #4
    Valued Member Exonaut is offline
    MemberRank
    Sep 2012 Join Date
    USALocation
    147Posts

    Re: issue with timermanager(i think?)

    Quote Originally Posted by super861 View Post
    @Exonaut , Thanks for the repsonse :) good to know why it didn't work too! I changed the timer event like yo usaid already (took a look in maplemap to see how its handled there and basicly copied that.), but now i know why it should be like this, so that's alwaus good.
    what i did was give the fishing method a boolean parameter, then in the function, if that's true, run the timer event. if its false, it checks if if fishtimerevent!= null, if so cancel the event. if its null, do nothing. your way looks a bit cleaner though. is it roughly the same as just making a boolean in maplecharacter with a getter and setter? or in this case just a setter. If that would be a "cleaner" way to do it, i'll be sure to code that in instead!

    I never knew about the empty function, so i'll be sure to take a look at that when i get back from work.

    thansk alot for taking the time to help :) my fishing system is starting to look better and better :D
    No problem, let me know if you have anymore problems.



Advertisement