001/******************************************************************************* 002 * Copyright (c) 2017 Red Hat Inc and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Red Hat Inc - initial API and implementation 011 *******************************************************************************/ 012package org.eclipse.kapua.gateway.client.mqtt.fuse.internal; 013 014import java.util.concurrent.CompletableFuture; 015 016import org.fusesource.mqtt.client.Callback; 017 018public final class Callbacks { 019 020 private Callbacks() { 021 } 022 023 public static <T> Callback<T> asCallback(CompletableFuture<T> future) { 024 return new Callback<T>() { 025 026 @Override 027 public void onSuccess(T value) { 028 future.complete(value); 029 } 030 031 @Override 032 public void onFailure(Throwable value) { 033 future.completeExceptionally(value); 034 } 035 }; 036 } 037}