1 /* 2 * #%L 3 * LegacyStreamCallbackAdapter.java - mongodb-async-driver - Allanbank Consulting, Inc. 4 * %% 5 * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 21 package com.allanbank.mongodb.client.callback; 22 23 import com.allanbank.mongodb.Callback; 24 import com.allanbank.mongodb.MongoCollection; 25 import com.allanbank.mongodb.StreamCallback; 26 import com.allanbank.mongodb.bson.Document; 27 28 /** 29 * LegacyStreamCallbackAdapter provides an adapter from a {@link Callback} to a 30 * {@link StreamCallback}. This adapter simulates the old behaviour specified in 31 * the 32 * {@link MongoCollection#streamingFind(Callback, com.allanbank.mongodb.bson.DocumentAssignable)} 33 * and 34 * {@link MongoCollection#streamingFind(Callback, com.allanbank.mongodb.builder.Find)} 35 * using the new interface. 36 * 37 * @api.no This class is <b>NOT</b> part of the drivers API. This class may be 38 * mutated in incompatible ways between any two releases of the driver. 39 * @deprecated Deprecated to ensure this class is removed with the 40 * {@link MongoCollection#streamingFind(Callback, com.allanbank.mongodb.bson.DocumentAssignable)} 41 * and 42 * {@link MongoCollection#streamingFind(Callback, com.allanbank.mongodb.builder.Find)} 43 * methods. 44 * @copyright 2013, Allanbank Consulting, Inc., All Rights Reserved 45 */ 46 @Deprecated 47 public final class LegacyStreamCallbackAdapter implements 48 StreamCallback<Document> { 49 50 /** The legacy callback to delegate to. */ 51 private final Callback<Document> myDelegate; 52 53 /** 54 * Creates a new LegacyStreamCallbackAdapter. 55 * 56 * @param delegate 57 * The legacy callback to delegate to. 58 */ 59 public LegacyStreamCallbackAdapter(final Callback<Document> delegate) { 60 myDelegate = delegate; 61 } 62 63 /** 64 * {@inheritDoc} 65 * <p> 66 * Overridden to forward to the legacy {@link Callback#callback}. 67 * </p> 68 */ 69 @Override 70 public void callback(final Document result) { 71 myDelegate.callback(result); 72 } 73 74 /** 75 * {@inheritDoc} 76 * <p> 77 * Overridden to forward to {@link Callback#callback callback(null)}. 78 * </p> 79 */ 80 @Override 81 public void done() { 82 myDelegate.callback(null); 83 } 84 85 /** 86 * {@inheritDoc} 87 * <p> 88 * Overridden to forward to the legacy {@link Callback#exception}. 89 * </p> 90 */ 91 @Override 92 public void exception(final Throwable thrown) { 93 myDelegate.exception(thrown); 94 } 95 }