import org.apache.catalina.CometEvent;
import org.apache.catalina.util.StringManager;
import org.apache.coyote.ActionCode;
+import org.apache.tomcat.util.net.PollerInterest;
public class CometEventImpl implements CometEvent {
for (CometEvent.CometOperation co : operations) {
if (!cometOperations.contains(co)) {
cometOperations.add(co);
- request.action(ActionCode.ACTION_COMET_REGISTER, co);
+ request.action(ActionCode.ACTION_COMET_REGISTER, translate(co));
}
}
}
for (CometEvent.CometOperation co : operations) {
if (cometOperations.contains(co)) {
cometOperations.remove(co);
- request.action(ActionCode.ACTION_COMET_UNREGISTER, co);
+ request.action(ActionCode.ACTION_COMET_UNREGISTER, translate(co));
}
}
}
throw new IllegalStateException("The operation can only be performed when invoked by a Tomcat worker thread.");
}
+ protected PollerInterest translate(CometOperation op) {
+ if ( op == CometEvent.CometOperation.OP_READ )
+ return PollerInterest.READ;
+ else if ( op == CometEvent.CometOperation.OP_WRITE )
+ return PollerInterest.WRITE;
+ else if ( op == CometEvent.CometOperation.OP_CALLBACK )
+ return PollerInterest.CALLBACK;
+ else
+ throw new IllegalArgumentException(op!=null?op.toString():"null");
+ }
+
//inner class used to keep track if the current thread is a worker thread.
private static class WorkerThreadCheck extends ThreadLocal {
}
+
+
}
import org.apache.tomcat.util.net.NioEndpoint.Handler.SocketState;
import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment;
+import org.apache.tomcat.util.net.PollerInterest;
/**
attach.setTimeout(to.longValue());
} else if (actionCode == ActionCode.ACTION_COMET_END) {
comet = false;
+ } else if (actionCode == ActionCode.ACTION_COMET_REGISTER) {
+ int interest = getPollerInterest(param);
+ NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+ attach.setCometOps(attach.getCometOps()|interest);
+ attach.getPoller().cometInterest(socket);
+ } else if (actionCode == ActionCode.ACTION_COMET_UNREGISTER) {
+ int interest = getPollerInterest(param);
+ NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+ attach.setCometOps(attach.getCometOps()& (~interest));
+ attach.getPoller().cometInterest(socket);
+ } else if (actionCode == ActionCode.ACTION_COMET_CONFIGURE) {
}
}
+ private int getPollerInterest(Object param) throws IllegalArgumentException {
+ if ( param == null || (!(param instanceof PollerInterest)) )
+ throw new IllegalArgumentException("Action parameter must be a PollerInterest object.");
+ int interest = 0;
+ PollerInterest pi = (PollerInterest)param;
+ if ( pi == PollerInterest.CALLBACK )
+ interest = NioEndpoint.OP_CALLBACK;
+ else if ( pi == PollerInterest.READ )
+ interest = SelectionKey.OP_READ;
+ else if ( pi == PollerInterest.WRITE )
+ interest = SelectionKey.OP_WRITE;
+ else
+ throw new IllegalArgumentException(pi!=null?pi.toString():"null");
+ return interest;
+ }
+
// ------------------------------------------------------ Connector Methods
*/
public static final String SESSION_ID_KEY = "javax.servlet.request.ssl_session";
- public static final int OP_REGISTER = -1; //register interest op
+ public static final int OP_REGISTER = 0x100; //register interest op
+ public static final int OP_CALLBACK = 0x200; //callback interest op
// ----------------------------------------------------------------- Fields
events.offer(event);
if ( wakeupCounter.incrementAndGet() < 3 ) selector.wakeup();
}
+
+ public void cometInterest(NioChannel socket) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void wakeup() {
+ selector.wakeup();
+ }
/**
* Add specified socket and associated pool to the poller. The socket will
public void access(long access) { lastAccess = access; }
public void setComet(boolean comet) { this.comet = comet; }
public boolean getComet() { return comet; }
+ public void setCometOps(int ops) { this.cometOps = ops; }
+ public int getCometOps() { return cometOps; }
public boolean getCurrentAccess() { return currentAccess; }
public void setCurrentAccess(boolean access) { currentAccess = access; }
public Object getMutex() {return mutex;}
protected long lastAccess = -1;
protected boolean currentAccess = false;
protected boolean comet = false;
+ protected int cometOps = 0;
protected long timeout = -1;
protected boolean error = false;
protected NioChannel channel = null;
--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.apache.tomcat.util.net;\r
+\r
+/**\r
+ * Different poller inter\r
+ * @author fhanik\r
+ */\r
+public enum PollerInterest {\r
+ READ, WRITE, CALLBACK;\r
+}\r