You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/08/05 18:46:35 UTC
svn commit: r801296 - in
/camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl:
CopyOnWriteMessageFacade.java ImmutableMessage.java
Author: davsclaus
Date: Wed Aug 5 16:46:35 2009
New Revision: 801296
URL: http://svn.apache.org/viewvc?rev=801296&view=rev
Log:
Added facade for copy on write experiment
Added:
camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java (with props)
camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java (with props)
Added: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java?rev=801296&view=auto
==============================================================================
--- camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java (added)
+++ camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java Wed Aug 5 16:46:35 2009
@@ -0,0 +1,178 @@
+/**
+ * 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.camel.impl;
+
+import java.util.Map;
+import java.util.Set;
+import javax.activation.DataHandler;
+
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.Exchange;
+
+/**
+ * @version $Revision$
+ */
+public class CopyOnWriteMessageFacade implements Message {
+ private Message readOnly;
+ private Message copiedMessage;
+
+ public CopyOnWriteMessageFacade(Message readOnly) {
+ this.readOnly = readOnly;
+ }
+
+ protected Message getDelegate() {
+ if (copiedMessage != null) {
+ return copiedMessage;
+ }
+ return readOnly;
+ }
+
+ protected Message ensureCopied() {
+ if (copiedMessage == null) {
+ copiedMessage = readOnly.copy();
+ }
+ return copiedMessage;
+ }
+
+ public Message copy() {
+ if (copiedMessage == null) {
+ // avoids actually coping the message if we've not yet modified it
+ return this;
+ } else {
+ return new CopyOnWriteMessageFacade(copiedMessage);
+ }
+ }
+
+ public void copyFrom(Message message) {
+ ensureCopied().copyFrom(message);
+ }
+
+ public Object getBody() {
+ return getDelegate().getBody();
+ }
+
+ public void setBody(Object value) {
+ ensureCopied().setBody(value);
+ }
+
+ public String getMessageId() {
+ return getDelegate().getMessageId();
+ }
+
+ public void setMessageId(String messageId) {
+ ensureCopied().setMessageId(messageId);
+ }
+
+ public Exchange getExchange() {
+ return getDelegate().getExchange();
+ }
+
+ public boolean isFault() {
+ return getDelegate().isFault();
+ }
+
+ public void setFault(boolean fault) {
+ ensureCopied().setFault(fault);
+ }
+
+ public Object getHeader(String name) {
+ return getDelegate().getHeader(name);
+ }
+
+ public <T> T getHeader(String name, Class<T> type) {
+ return getDelegate().getHeader(name, type);
+ }
+
+ public void setHeader(String name, Object value) {
+ ensureCopied().setHeader(name, value);
+ }
+
+ public Object removeHeader(String name) {
+ return ensureCopied().removeHeader(name);
+ }
+
+ public Map<String, Object> getHeaders() {
+ return getDelegate().getHeaders();
+ }
+
+ public void setHeaders(Map<String, Object> headers) {
+ ensureCopied().setHeaders(headers);
+ }
+
+ public boolean hasHeaders() {
+ return getDelegate().hasHeaders();
+ }
+
+ public Object getMandatoryBody() throws InvalidPayloadException {
+ return getDelegate().getMandatoryBody();
+ }
+
+ public <T> T getBody(Class<T> type) {
+ return getDelegate().getBody(type);
+ }
+
+ public <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException {
+ return getDelegate().getMandatoryBody(type);
+ }
+
+ public <T> void setBody(Object body, Class<T> type) {
+ ensureCopied().setBody(body, type);
+ }
+
+ public DataHandler getAttachment(String id) {
+ return getDelegate().getAttachment(id);
+ }
+
+ public Set<String> getAttachmentNames() {
+ return getDelegate().getAttachmentNames();
+ }
+
+ public void removeAttachment(String id) {
+ ensureCopied().removeAttachment(id);
+ }
+
+ public void addAttachment(String id, DataHandler content) {
+ ensureCopied().addAttachment(id, content);
+ }
+
+ public Map<String, DataHandler> getAttachments() {
+ return getDelegate().getAttachments();
+ }
+
+ public void setAttachments(Map<String, DataHandler> attachments) {
+ ensureCopied().setAttachments(attachments);
+ }
+
+ public boolean hasAttachments() {
+ return getDelegate().hasAttachments();
+ }
+
+ public String createExchangeId() {
+ return getDelegate().createExchangeId();
+ }
+
+ @Override
+ public String toString() {
+ if (copiedMessage != null) {
+ return copiedMessage.toString();
+ }
+ return readOnly.toString();
+ }
+}
+
+
Propchange: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java?rev=801296&view=auto
==============================================================================
--- camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java (added)
+++ camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java Wed Aug 5 16:46:35 2009
@@ -0,0 +1,158 @@
+/**
+ * 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.camel.impl;
+
+import java.util.Map;
+import java.util.Set;
+import javax.activation.DataHandler;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+
+/**
+ * @version $Revision$
+ */
+public class ImmutableMessage implements Message {
+
+ private Message readOnly;
+
+ private void throwImmutableError() {
+ throw new RuntimeException("Not possbile. Add a better exception type and description");
+ }
+
+ private Message getDelegate() {
+ return readOnly;
+ }
+
+ public ImmutableMessage(Message readOnly) {
+ this.readOnly = readOnly;
+ }
+
+ public String getMessageId() {
+ return getDelegate().getMessageId();
+ }
+
+ public void setMessageId(String messageId) {
+ throwImmutableError();
+ }
+
+ public Exchange getExchange() {
+ return getDelegate().getExchange();
+ }
+
+ public boolean isFault() {
+ return getDelegate().isFault();
+ }
+
+ public void setFault(boolean fault) {
+ throwImmutableError();
+ }
+
+ public Object getHeader(String name) {
+ return getDelegate().getHeader(name);
+ }
+
+ public <T> T getHeader(String name, Class<T> type) {
+ return getDelegate().getHeader(name, type);
+ }
+
+ public void setHeader(String name, Object value) {
+ throwImmutableError();
+ }
+
+ public Object removeHeader(String name) {
+ throwImmutableError();
+ return null;
+ }
+
+ public Map<String, Object> getHeaders() {
+ return getDelegate().getHeaders();
+ }
+
+ public void setHeaders(Map<String, Object> headers) {
+ throwImmutableError();
+ }
+
+ public boolean hasHeaders() {
+ return getDelegate().hasHeaders();
+ }
+
+ public Object getBody() {
+ return getDelegate().getBody();
+ }
+
+ public Object getMandatoryBody() throws InvalidPayloadException {
+ return getDelegate().getMandatoryBody();
+ }
+
+ public <T> T getBody(Class<T> type) {
+ return getDelegate().getBody(type);
+ }
+
+ public <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException {
+ return getDelegate().getMandatoryBody(type);
+ }
+
+ public void setBody(Object body) {
+ throwImmutableError();
+ }
+
+ public <T> void setBody(Object body, Class<T> type) {
+ throwImmutableError();
+ }
+
+ public Message copy() {
+ return this;
+ }
+
+ public void copyFrom(Message message) {
+ throwImmutableError();
+ }
+
+ public DataHandler getAttachment(String id) {
+ return getDelegate().getAttachment(id);
+ }
+
+ public Set<String> getAttachmentNames() {
+ return getDelegate().getAttachmentNames();
+ }
+
+ public void removeAttachment(String id) {
+ throwImmutableError();
+ }
+
+ public void addAttachment(String id, DataHandler content) {
+ throwImmutableError();
+ }
+
+ public Map<String, DataHandler> getAttachments() {
+ return getDelegate().getAttachments();
+ }
+
+ public void setAttachments(Map<String, DataHandler> attachments) {
+ throwImmutableError();
+ }
+
+ public boolean hasAttachments() {
+ return getDelegate().hasAttachments();
+ }
+
+ public String createExchangeId() {
+ return getDelegate().createExchangeId();
+ }
+}
Propchange: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/ImmutableMessage.java
------------------------------------------------------------------------------
svn:keywords = Rev Date