Home » activemq-parent-5.3.1-source-release » org.apache » activemq » blob » [javadoc | source]

    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   import java.net.MalformedURLException;
   20   import java.net.URL;
   21   
   22   /**
   23    * The policy for configuring how BLOBs (Binary Large OBjects) are transferred
   24    * out of band between producers, brokers and consumers.
   25    *
   26    * @version $Revision: $
   27    */
   28   public class BlobTransferPolicy {
   29       private String defaultUploadUrl = "http://localhost:8080/uploads/";
   30       private String brokerUploadUrl;
   31       private String uploadUrl;
   32       private int bufferSize = 128 * 1024;
   33       private BlobUploadStrategy uploadStrategy;
   34       private BlobDownloadStrategy downloadStrategy;
   35   
   36       /**
   37        * Returns a copy of this policy object
   38        */
   39       public BlobTransferPolicy copy() {
   40           BlobTransferPolicy that = new BlobTransferPolicy();
   41           that.defaultUploadUrl = this.defaultUploadUrl;
   42           that.brokerUploadUrl = this.brokerUploadUrl;
   43           that.uploadUrl = this.uploadUrl;
   44           that.uploadStrategy = this.uploadStrategy;
   45           return that;
   46       }
   47   
   48       public String getUploadUrl() {
   49           if (uploadUrl == null) {
   50               uploadUrl = getBrokerUploadUrl();
   51               if (uploadUrl == null) {
   52                   uploadUrl = getDefaultUploadUrl();
   53               }
   54           }
   55           return uploadUrl;
   56       }
   57   
   58       /**
   59        * Sets the upload URL to use explicitly on the client which will
   60        * overload the default or the broker's URL. This allows the client to decide
   61        * where to upload files to irrespective of the brokers configuration.
   62        */
   63       public void setUploadUrl(String uploadUrl) {
   64           this.uploadUrl = uploadUrl;
   65       }
   66   
   67       public String getBrokerUploadUrl() {
   68           return brokerUploadUrl;
   69       }
   70   
   71       /**
   72        * Called by the JMS client when a broker advertises its upload URL
   73        */
   74       public void setBrokerUploadUrl(String brokerUploadUrl) {
   75           this.brokerUploadUrl = brokerUploadUrl;
   76       }
   77   
   78       public String getDefaultUploadUrl() {
   79           return defaultUploadUrl;
   80       }
   81   
   82       /**
   83        * Sets the default upload URL to use if the broker does not
   84        * have a configured upload URL
   85        */
   86       public void setDefaultUploadUrl(String defaultUploadUrl) {
   87           this.defaultUploadUrl = defaultUploadUrl;
   88       }
   89   
   90       public BlobUploadStrategy getUploadStrategy() {
   91           if (uploadStrategy == null) {
   92               uploadStrategy = createUploadStrategy();
   93           }
   94           return uploadStrategy;
   95       }
   96   
   97       public BlobDownloadStrategy getDownloadStrategy() {
   98           if(downloadStrategy == null) {
   99               downloadStrategy = createDownloadStrategy();
  100           }
  101           return downloadStrategy;
  102       }
  103   
  104       /**
  105        * Sets the upload strategy to use for uploading BLOBs to some URL
  106        */
  107       public void setUploadStrategy(BlobUploadStrategy uploadStrategy) {
  108           this.uploadStrategy = uploadStrategy;
  109       }
  110   
  111       public int getBufferSize() {
  112           return bufferSize;
  113       }
  114   
  115       /**
  116        * Sets the default buffer size used when uploading or downloading files
  117        */
  118       public void setBufferSize(int bufferSize) {
  119           this.bufferSize = bufferSize;
  120       }
  121   
  122       /**
  123        * Returns the upload strategy depending on the information from the
  124        * uploadURL. Currently supportet HTTP and FTP
  125        * 
  126        * @return
  127        */
  128       protected BlobUploadStrategy createUploadStrategy() {
  129       	BlobUploadStrategy strategy;
  130       	try {
  131               URL url = new URL(getUploadUrl());
  132   
  133               if(url.getProtocol().equalsIgnoreCase("FTP")) {
  134                   strategy = new FTPBlobUploadStrategy(this);
  135               } else {
  136                   strategy = new DefaultBlobUploadStrategy(this);
  137       }
  138           } catch (MalformedURLException e) {
  139                   strategy = new DefaultBlobUploadStrategy(this);
  140   }
  141           return strategy;
  142       }
  143       
  144       /**
  145        * Returns the download strategy depending on the information from the
  146        * uploadURL. Currently supportet HTTP and FTP
  147        * 
  148        * @return
  149        */
  150       protected BlobDownloadStrategy createDownloadStrategy() {
  151           BlobDownloadStrategy strategy;
  152           try {
  153               URL url = new URL(getUploadUrl());
  154               
  155               if(url.getProtocol().equalsIgnoreCase("FTP")) {
  156                   strategy = new FTPBlobDownloadStrategy();
  157               } else {
  158                   strategy = new DefaultBlobDownloadStrategy();
  159               }
  160           } catch (MalformedURLException e) {
  161               strategy = new DefaultBlobDownloadStrategy();
  162           }
  163           return strategy;
  164       }
  165   
  166       
  167   }

Home » activemq-parent-5.3.1-source-release » org.apache » activemq » blob » [javadoc | source]