KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > store > amq > RecoveryListenerAdapter


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

14
15 package org.apache.activemq.store.amq;
16
17 import org.apache.activemq.command.Message;
18 import org.apache.activemq.command.MessageId;
19 import org.apache.activemq.store.MessageRecoveryListener;
20 import org.apache.activemq.store.MessageStore;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 final class RecoveryListenerAdapter implements MessageRecoveryListener{
25
26     static final private Log log=LogFactory.getLog(RecoveryListenerAdapter.class);
27     private final MessageStore store;
28     private final MessageRecoveryListener listener;
29     private int count=0;
30     private MessageId lastRecovered;
31
32     RecoveryListenerAdapter(MessageStore store,MessageRecoveryListener listener){
33         this.store=store;
34         this.listener=listener;
35     }
36
37     public void finished(){
38         listener.finished();
39     }
40
41     public boolean hasSpace(){
42         return listener.hasSpace();
43     }
44
45     public void recoverMessage(Message message) throws Exception JavaDoc{
46         listener.recoverMessage(message);
47         lastRecovered=message.getMessageId();
48         count++;
49     }
50
51     public void recoverMessageReference(MessageId ref) throws Exception JavaDoc{
52         Message message=this.store.getMessage(ref);
53         if(message!=null){
54             recoverMessage(message);
55         }else{
56             log.error("Message id "+ref+" could not be recovered from the data store!");
57         }
58     }
59     
60     MessageId getLastRecoveredMessageId() {
61         return lastRecovered;
62     }
63
64     int size(){
65         return count;
66     }
67
68     void reset(){
69         count=0;
70     }
71 }
72
Popular Tags