Author: fhanik
Date: Thu Jul 5 13:50:13 2007
New Revision: 553628
URL: http://svn.apache.org/viewvc?view=rev&rev=553628
Log:
Added license headers
Implemented a streaming parser for JSON reading, so that we can read data
directly from the reader without having to parse it twice
Added:
tomcat/sandbox/bayeux/java/org/apache/comet/json/
tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java
Modified:
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxChannel.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxClient.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxFilter.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxListener.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxPolicy.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxServlet.java
tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/TomcatBayeux.java
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxChannel.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxChannel.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxChannel.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxChannel.java Thu
Jul 5 13:50:13 2007
@@ -1,8 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import dojox.cometd.Channel;
import dojox.cometd.Client;
-
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxChannel implements Channel {
public BayeuxChannel() {
}
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxClient.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxClient.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxClient.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxClient.java Thu
Jul 5 13:50:13 2007
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import java.util.Map;
@@ -5,6 +21,10 @@
import dojox.cometd.Client;
import dojox.cometd.Listener;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxClient implements Client {
public BayeuxClient() {
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxFilter.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxFilter.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxFilter.java Thu
Jul 5 13:50:13 2007
@@ -1,8 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import dojox.cometd.Channel;
import dojox.cometd.Client;
import dojox.cometd.DataFilter;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxFilter implements DataFilter {
public BayeuxFilter() {
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxListener.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxListener.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxListener.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxListener.java Thu
Jul 5 13:50:13 2007
@@ -1,7 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import dojox.cometd.Client;
import dojox.cometd.Listener;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxListener implements Listener {
public BayeuxListener() {
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxPolicy.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxPolicy.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxPolicy.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxPolicy.java Thu
Jul 5 13:50:13 2007
@@ -1,9 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import java.util.Map;
import dojox.cometd.Client;
import dojox.cometd.SecurityPolicy;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxPolicy implements SecurityPolicy {
public BayeuxPolicy() {
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxServlet.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxServlet.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxServlet.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/BayeuxServlet.java Thu
Jul 5 13:50:13 2007
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import java.io.IOException;
@@ -9,11 +25,22 @@
import org.apache.catalina.CometEvent;
import org.apache.catalina.CometProcessor;
import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import org.apache.catalina.CometEvent.CometOperation;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class BayeuxServlet implements CometProcessor {
protected ServletConfig servletConfig;
+ /**
+ * Complete list of all active events
+ */
+ protected ArrayList<CometEvent> events = new ArrayList<CometEvent>();
+
public BayeuxServlet() {
}
@@ -34,9 +61,46 @@
* @throws ServletException
* @todo Implement this org.apache.catalina.CometProcessor method
*/
- public void event(CometEvent cometEvent) throws IOException,
ServletException {
+ public void event(CometEvent event) throws IOException, ServletException {
+ if (event.getEventType()==CometEvent.EventType.BEGIN) {
+ eventBegin(event);
+ }else if (event.getEventType()==CometEvent.EventType.READ) {
+ eventRead(event);
+ }else if (event.getEventType()==CometEvent.EventType.END) {
+ eventEnd(event);
+ }else if (event.getEventType()==CometEvent.EventType.ERROR) {
+ eventEnd(event);
+ }else if (event.getEventType()==CometEvent.EventType.WRITE) {
+ //noop at this time, unregister the event
+ event.unregister(CometOperation.OP_WRITE);
+ }else if (event.getEventType()==CometEvent.EventType.CALLBACK) {
+ //noop at this time, unregister the event
+ event.unregister(CometOperation.OP_CALLBACK);
+ }
+ }
+
+ public void eventBegin(CometEvent event) throws IOException,
ServletException {
+ if (!events.contains(event)) {
+ events.add(event);
+ event.configureBlocking(true);
+ event.register(CometOperation.OP_READ);
+ } else {
+ //somehow an event got reused and we have it cached already
+ //can't do anything but to close it
+ event.close();
+ }
+ }
+
+ public void eventRead(CometEvent event) throws IOException,
ServletException {
}
+
+ public void eventEnd(CometEvent event) throws IOException,
ServletException {
+ events.remove(event);
+ event.close();
+ }
+
+
/**
* getServletConfig
Modified: tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/TomcatBayeux.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/TomcatBayeux.java?view=diff&rev=553628&r1=553627&r2=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/TomcatBayeux.java
(original)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/bayeux/TomcatBayeux.java Thu
Jul 5 13:50:13 2007
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.comet.bayeux;
import dojox.cometd.Bayeux;
@@ -6,6 +22,10 @@
import dojox.cometd.DataFilter;
import dojox.cometd.Listener;
import dojox.cometd.SecurityPolicy;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
public class TomcatBayeux implements Bayeux {
public TomcatBayeux() {
Added: tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java?view=auto&rev=553628
==============================================================================
--- tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java
(added)
+++ tomcat/sandbox/bayeux/java/org/apache/comet/json/ReaderCharIterator.java
Thu Jul 5 13:50:13 2007
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.comet.json;
+
+import java.text.CharacterIterator;
+import java.io.Reader;
+import java.io.EOFException;
+import java.io.IOException;
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
+
+public class ReaderCharIterator implements CharacterIterator {
+ /**
+ * The reader used to read characters from
+ */
+ protected Reader reader = null;
+
+ /**
+ * The buffer of characters held
+ */
+ protected StringBuffer buffer = new StringBuffer();
+
+ /**
+ * Position for the character reader
+ * if pos==buffer.length, then we need to read data
+ */
+ protected int pos = -1;
+
+ /**
+ *
+ * @param r Reader
+ */
+ public ReaderCharIterator(Reader r) {
+ this.reader = r;
+ }
+
+
+ public void recycle() {
+ reader = null;
+ buffer.delete(0,buffer.length());
+ }
+
+ public void setReader(Reader r){
+ this.reader = r;
+ }
+
+ public Reader getReader() {
+ return reader;
+ }
+
+ public void read() {
+ try {
+ int c = reader.read();
+ if (c == -1)
+ throw new RuntimeException(new EOFException());
+ buffer.append((char)c);
+ }catch (IOException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+//=============================================================================
+// CharacterIterator implementation
+//=============================================================================
+ /**
+ * Gets the character at the current position (as returned by getIndex()).
+ *
+ * @return the character at the current position or DONE if the current
position is off the end of the text.
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char current() {
+ return buffer.charAt(pos);
+ }
+
+ /**
+ * Sets the position to getBeginIndex() and returns the character at that
position.
+ *
+ * @return the first character in the text, or DONE if the text is empty
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char first() {
+ if (buffer.length()==0) read();
+ pos = 0;
+ return buffer.charAt(pos);
+ }
+
+ /**
+ * Returns the start index of the text.
+ *
+ * @return the index at which the text begins.
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public int getBeginIndex() {
+ return 0;
+ }
+
+ /**
+ * Returns the end index of the text.
+ *
+ * @return the index after the last character in the text
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public int getEndIndex() {
+ if (buffer.length()==0) return 0;
+ return buffer.length()-1;
+ }
+
+ /**
+ * Returns the current index.
+ *
+ * @return the current index.
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public int getIndex() {
+ return pos;
+ }
+
+ /**
+ * Sets the position to getEndIndex()-1 (getEndIndex() if the text is
empty) and returns the character at that
+ * position.
+ *
+ * @return the last character in the text, or DONE if the text is empty
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char last() {
+ throw new IllegalStateException("Streaming iterator, last() is
unknown");
+ }
+
+ /**
+ * Increments the iterator's index by one and returns the character at the
new index.
+ *
+ * @return the character at the new position or DONE if the new position
is off the end of the text range.
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char next() {
+ pos++;
+ if (buffer.length()==0 || pos==buffer.length()) read();
+ return buffer.charAt(pos);
+ }
+
+ /**
+ * Decrements the iterator's index by one and returns the character at the
new index.
+ *
+ * @return the character at the new position or DONE if the current
position is equal to getBeginIndex().
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char previous() {
+ pos--;
+ return buffer.charAt(pos);
+ }
+
+ /**
+ * Sets the position to the specified position in the text and returns
that character.
+ *
+ * @param position the position within the text. Valid values range from
getBeginIndex() to getEndIndex(). An
+ * IllegalArgumentException is thrown if an invalid value is supplied.
+ * @return the character at the specified position or DONE if the
specified position is equal to getEndIndex()
+ * @todo Implement this java.text.CharacterIterator method
+ */
+ public char setIndex(int position) {
+ pos = position;
+ return buffer.charAt(pos);
+ }
+
+ public Object clone() {
+ ReaderCharIterator rci = new ReaderCharIterator(getReader());
+ rci.buffer = new StringBuffer(buffer.toString());
+ rci.pos = this.pos;
+ return rci;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]