public Http4K unPublishHandler(String urlPath, int port) { Pair<PathHandler, Undertow> server = serverMap.get(port); if (server!=null) { server.car().removePrefixPath(urlPath); } return this; } }
public void triggerLongPoll() { synchronized (this) { if (longPollTask!=null) { if ( LP_DEBUG ) System.out.println("SEND PENDING "+triggerPending); if (triggerPending.get() > 0) // fixme: concurrency bug triggerPending.decrementAndGet(); Runnable car = longPollTask.car(); longPollTask = null; car.run(); } else { if ( LP_DEBUG ) System.out.println("INC PENDING "+triggerPending); triggerPending.incrementAndGet(); } } }
public Diff reduced(String[] reducedFields) { ArrayList<Pair<String,Object>> newDiff = new ArrayList(); for (int i = 0; i < changedFields.length; i++) { String changedField = changedFields[i]; for (int j = 0; j < reducedFields.length; j++) { String reducedField = reducedFields[j]; if ( changedField.equals(reducedField) ) { newDiff.add(new Pair(reducedField,oldValues[i])); } } } String newChanged[] = new String[newDiff.size()]; Object newVals[] = new Object[newDiff.size()]; for (int i = 0; i < newDiff.size(); i++) { Pair<String, Object> stringObjectPair = newDiff.get(i); newChanged[i] = stringObjectPair.car(); newVals[i] = stringObjectPair.cdr(); } return new Diff(newChanged,newVals); }
public Http4K publishHandler(String hostName, String urlPath, int port, HttpHandler handler) { Pair<PathHandler, Undertow> server = getServer(port, hostName); server.car().addPrefixPath( urlPath, handler); return this; }
public Http4K publishFileSystem( String hostName, String urlPath, int port, FileResourceManager man ) { if ( ! man.getBase().isDirectory() ) { throw new RuntimeException("root must be an existing direcory:"+man.getBase().getAbsolutePath()); } Pair<PathHandler, Undertow> server = getServer(port, hostName); server.car().addPrefixPath(urlPath, new ResourceHandler(man )); return this; } public Http4K publishResourcePath( String hostName, String urlPath, int port, DynamicResourceManager man, boolean compress ) {
/** * publishes given file root * @param hostName * @param urlPath - prefixPath (e.g. /myapp/resource) * @param port * @param root - directory to be published */ public Http4K publishFileSystem( String hostName, String urlPath, int port, File root ) { if ( ! root.exists() ) root.mkdirs(); if ( ! root.isDirectory() ) { throw new RuntimeException("root must be an existing direcory:"+root.getAbsolutePath()); } Pair<PathHandler, Undertow> server = getServer(port, hostName); server.car().addPrefixPath(urlPath, new ResourceHandler(new FileResourceManager(root,100))); return this; }
exchange.endExchange(); } else if ( r instanceof Pair ) { exchange.setStatusCode((Integer) ((Pair) r).car()); exchange.getResponseSender().send(""+((Pair) r).cdr()); } else if ( r instanceof JsonValue ) {