001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.cli; 020 021import java.rmi.registry.Registry; 022import java.rmi.server.UnicastRemoteObject; 023 024public class Closer extends Thread { 025 026 private String name; 027 private Registry reg; 028 private long idleTime; 029 private CLIInvokerImpl invoker; 030 031 public Closer(Registry reg, CLIInvokerImpl invoker, String name, long idleTime) { 032 this.reg=reg; 033 this.name=name; 034 this.idleTime=idleTime; 035 this.invoker=invoker; 036 } 037 038 public void run() { 039 // idle 040 do{ 041 sleepEL(idleTime); 042 } 043 while(invoker.lastAccess()+idleTime>System.currentTimeMillis()); 044 045 046 try { 047 reg.unbind(name); 048 UnicastRemoteObject.unexportObject(invoker,true); 049 } catch (Throwable t) { 050 if(t instanceof ThreadDeath) throw (ThreadDeath)t; 051 t.printStackTrace(); 052 } 053 054 } 055 056 private void sleepEL(long millis) { 057 try { 058 sleep(millis); 059 } catch (Throwable t) { 060 if(t instanceof ThreadDeath) throw (ThreadDeath)t; 061 t.printStackTrace(); 062 } 063 } 064 065}