added comments

This commit is contained in:
Amer Agovic
2024-01-21 21:48:39 -06:00
parent feb5d4c163
commit 222d2d886f
6 changed files with 10 additions and 4 deletions
+1
View File
@@ -31,6 +31,7 @@ public class Bag<E> extends Observable implements Collection<E>{
final Bag<E> bag; final Bag<E> bag;
final int operation; final int operation;
final Object[] arguments; final Object[] arguments;
public BagChanged(Bag<E> p,int op,Object ... args){ public BagChanged(Bag<E> p,int op,Object ... args){
bag=p; bag=p;
operation=op; operation=op;
+3 -1
View File
@@ -170,10 +170,11 @@ public abstract class App extends Processor{
} }
return null; return null;
} }
/** return special processor which dispatches request.s */
public Router getRouter() { public Router getRouter() {
return router; return router;
} }
/** sets the main request dispatcher. */
public void setRouter(Router router) { public void setRouter(Router router) {
if(this.router==router) return; if(this.router==router) return;
if(this.router!=null) this.router.setParent(null); if(this.router!=null) this.router.setParent(null);
@@ -232,6 +233,7 @@ public abstract class App extends Processor{
public AppSessionFilter addAppSession(AppSession.Factory f){ public AppSessionFilter addAppSession(AppSession.Factory f){
return addMiddleWare(new AppSessionFilter(this,f)); return addMiddleWare(new AppSessionFilter(this,f));
} }
/** set security policy which will recover users and also enforce permissions. */
public SecurityPolicy setSecurityPolicy(SecurityPolicy secpol){ public SecurityPolicy setSecurityPolicy(SecurityPolicy secpol){
if(secpol==policy) return secpol; if(secpol==policy) return secpol;
if(policy!=null){ if(policy!=null){
@@ -15,6 +15,7 @@ import java.util.UUID;
* and based on it install an app wide sesson dictionary. * and based on it install an app wide sesson dictionary.
*/ */
public class AppSessionFilter extends Processor{ public class AppSessionFilter extends Processor{
/**special key to identify session cookie. */
public static final String KEY_NAME="jbssid"; public static final String KEY_NAME="jbssid";
AppSession.Factory factory; AppSession.Factory factory;
App app; App app;
@@ -64,6 +64,7 @@ public class JettyApp extends App implements Handler{
jetty = new Server(); jetty = new Server();
jetty.setHandler(this); jetty.setHandler(this);
_state=State.STOPPED; _state=State.STOPPED;
this.addShutdownHook();
} }
public Connector[] getConnectors(){ public Connector[] getConnectors(){
if(connectors!=null) return connectors; if(connectors!=null) return connectors;
@@ -216,7 +217,7 @@ public class JettyApp extends App implements Handler{
* ctrl-c works but does not perform our shutdown sequence. * ctrl-c works but does not perform our shutdown sequence.
* this code interrupts jetty and then waits for app to finish. * this code interrupts jetty and then waits for app to finish.
*/ */
public void addShutdownHook(){ protected final void addShutdownHook(){
final JettyApp app=this; final JettyApp app=this;
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if(app.isRunning()){ if(app.isRunning()){
@@ -268,7 +269,6 @@ public class JettyApp extends App implements Handler{
public static void main( String[] args ) throws Exception{ public static void main( String[] args ) throws Exception{
Config cnf=new ArgsConfig(args).load(); Config cnf=new ArgsConfig(args).load();
JettyApp app=new JettyApp(); JettyApp app=new JettyApp();
app.addShutdownHook();
app.run(cnf); app.run(cnf);
} }
@@ -109,7 +109,10 @@ public abstract class Processor {
if(ret==null) ret=logger=LoggerFactory.getLogger(this.getId()); if(ret==null) ret=logger=LoggerFactory.getLogger(this.getId());
return ret; return ret;
} }
/** called before serve. */
public abstract void before(Request request,Response response) throws IOException; public abstract void before(Request request,Response response) throws IOException;
/** called after serve. */
public abstract void after(Request request,Response response) throws IOException; public abstract void after(Request request,Response response) throws IOException;
/** main processing and subprocessing happens here. */
public abstract void serve(Request request,Response response) throws IOException; public abstract void serve(Request request,Response response) throws IOException;
} }
@@ -24,7 +24,6 @@ public class DemoApp extends JettyApp implements AppModule{
public static void main( String[] args ) throws Exception{ public static void main( String[] args ) throws Exception{
Config cnf=new ArgsConfig(args).load(); Config cnf=new ArgsConfig(args).load();
JettyApp app=new DemoApp(); JettyApp app=new DemoApp();
app.addShutdownHook();
app.run(cnf); app.run(cnf);
} }
/** called from begin just before jetty starts. /** called from begin just before jetty starts.