Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 1157:50879022f49d
failed attempt to remove Http.per_session_pages
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 05 Feb 2018 01:25:42 -0700 |
parents | 151dc95f5e73 |
children | 3ef883468fd0 |
comparison
equal
deleted
inserted
replaced
1156:3839ecc130ea | 1157:50879022f49d |
---|---|
1 package luan.modules; | 1 package luan.modules; |
2 | 2 |
3 import java.io.Closeable; | 3 import java.io.Closeable; |
4 import java.util.Iterator; | |
4 import java.util.Map; | 5 import java.util.Map; |
6 import java.util.HashMap; | |
5 import java.util.LinkedHashMap; | 7 import java.util.LinkedHashMap; |
6 import java.util.concurrent.Executor; | 8 import java.util.concurrent.Executor; |
7 import java.util.concurrent.Executors; | 9 import java.util.concurrent.Executors; |
8 import java.util.concurrent.ScheduledThreadPoolExecutor; | 10 import java.util.concurrent.ScheduledThreadPoolExecutor; |
9 import java.util.concurrent.ScheduledFuture; | 11 import java.util.concurrent.ScheduledFuture; |
109 | 111 |
110 | 112 |
111 public static void sleep(long millis) throws InterruptedException { | 113 public static void sleep(long millis) throws InterruptedException { |
112 Thread.sleep(millis); | 114 Thread.sleep(millis); |
113 } | 115 } |
116 | |
117 | |
118 /* | |
119 private static boolean isPrimitive(Object v) { | |
120 if( v instanceof Object[] ) { | |
121 Object[] a = (Object[])v; | |
122 for( Object obj : a ) { | |
123 if( !isPrimitive(obj) ) | |
124 return false; | |
125 } | |
126 return true; | |
127 } else { | |
128 return v==null || v instanceof String || v instanceof Boolean || v instanceof Number; | |
129 } | |
130 } | |
131 | |
132 public static final class Callable { | |
133 private long expires; | |
134 private final LuanState luan = new LuanState(); | |
135 private final LuanTable fns; | |
136 | |
137 Callable(LuanState luan,LuanTable fns) { | |
138 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); | |
139 this.fns = (LuanTable)cloner.get(fns); | |
140 } | |
141 | |
142 public synchronized Object call(String fnName,Object... args) throws LuanException { | |
143 if( !isPrimitive(args) ) | |
144 throw new LuanException("can't pass non-primitive type to global_callable"); | |
145 Object f = fns.get(luan,fnName); | |
146 if( f == null ) | |
147 throw new LuanException("function '"+fnName+"' not found in global_callable"); | |
148 if( !(f instanceof LuanFunction) ) | |
149 throw new LuanException("value of '"+fnName+"' not a function in global_callable"); | |
150 LuanFunction fn = (LuanFunction)f; | |
151 Object rtn = fn.call(luan,args); | |
152 if( !isPrimitive(rtn) ) | |
153 throw new LuanException("can't return non-primitive type from global_callable"); | |
154 return rtn; | |
155 } | |
156 } | |
157 | |
158 private static Map<String,Callable> callableMap = new HashMap<String,Callable>(); | |
159 | |
160 private static void sweep() { | |
161 long now = System.currentTimeMillis(); | |
162 for( Iterator<Callable> iter = callableMap.values().iterator(); iter.hasNext(); ) { | |
163 Callable callable = iter.next(); | |
164 if( callable.expires < now ) | |
165 iter.remove(); | |
166 } | |
167 } | |
168 | |
169 public static synchronized Callable globalCallable(LuanState luan,String name,long timeout,LuanTable fns) { | |
170 Callable callable = callableMap.get(name); | |
171 if( callable == null ) { | |
172 sweep(); | |
173 callable = new Callable(luan,fns); | |
174 callableMap.put(name,callable); | |
175 } | |
176 callable.expires = System.currentTimeMillis() + timeout; | |
177 return callable; | |
178 } | |
179 */ | |
114 } | 180 } |