KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > blob > BlobTransferPolicy


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.activemq.blob;
18
19 /**
20  * The policy for configuring how BLOBs (Binary Large OBjects) are transferred
21  * out of band between producers, brokers and consumers.
22  *
23  * @version $Revision: $
24  */

25 public class BlobTransferPolicy {
26     private String JavaDoc defaultUploadUrl = "http://localhost:8080/uploads/";
27     private String JavaDoc brokerUploadUrl;
28     private String JavaDoc uploadUrl;
29     private int bufferSize = 128 * 1024;
30     private BlobUploadStrategy uploadStrategy;
31
32     /**
33      * Returns a copy of this policy object
34      */

35     public BlobTransferPolicy copy() {
36         BlobTransferPolicy that = new BlobTransferPolicy();
37         that.defaultUploadUrl = this.defaultUploadUrl;
38         that.brokerUploadUrl = this.brokerUploadUrl;
39         that.uploadUrl = this.uploadUrl;
40         that.uploadStrategy = this.uploadStrategy;
41         return that;
42     }
43
44     public String JavaDoc getUploadUrl() {
45         if (uploadUrl == null) {
46             uploadUrl = getBrokerUploadUrl();
47             if (uploadUrl == null) {
48                 uploadUrl = getDefaultUploadUrl();
49             }
50         }
51         return uploadUrl;
52     }
53
54     /**
55      * Sets the upload URL to use explicitly on the client which will
56      * overload the default or the broker's URL. This allows the client to decide
57      * where to upload files to irrespective of the brokers configuration.
58      */

59     public void setUploadUrl(String JavaDoc uploadUrl) {
60         this.uploadUrl = uploadUrl;
61     }
62
63     public String JavaDoc getBrokerUploadUrl() {
64         return brokerUploadUrl;
65     }
66
67     /**
68      * Called by the JMS client when a broker advertises its upload URL
69      */

70     public void setBrokerUploadUrl(String JavaDoc brokerUploadUrl) {
71         this.brokerUploadUrl = brokerUploadUrl;
72     }
73
74     public String JavaDoc getDefaultUploadUrl() {
75         return defaultUploadUrl;
76     }
77
78     /**
79      * Sets the default upload URL to use if the broker does not
80      * have a configured upload URL
81      */

82     public void setDefaultUploadUrl(String JavaDoc defaultUploadUrl) {
83         this.defaultUploadUrl = defaultUploadUrl;
84     }
85
86     public BlobUploadStrategy getUploadStrategy() {
87         if (uploadStrategy == null) {
88             uploadStrategy = createUploadStrategy();
89         }
90         return uploadStrategy;
91     }
92
93     /**
94      * Sets the upload strategy to use for uploading BLOBs to some URL
95      */

96     public void setUploadStrategy(BlobUploadStrategy uploadStrategy) {
97         this.uploadStrategy = uploadStrategy;
98     }
99
100     public int getBufferSize() {
101         return bufferSize;
102     }
103
104     /**
105      * Sets the default buffer size used when uploading or downloading files
106      */

107     public void setBufferSize(int bufferSize) {
108         this.bufferSize = bufferSize;
109     }
110
111     protected BlobUploadStrategy createUploadStrategy() {
112         return new DefaultBlobUploadStrategy(this);
113     }
114 }
115
Popular Tags