andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * jndn-management |
| 3 | * Copyright (c) 2015, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU Lesser General Public License, |
| 7 | * version 3, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 12 | * more details. |
| 13 | */ |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 14 | |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 15 | package com.intel.jndn.management; |
| 16 | |
Alexander Afanasyev | 499aced | 2016-02-17 19:32:37 -0800 | [diff] [blame] | 17 | import net.named_data.jndn.ControlResponse; |
| 18 | |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Represent a failure to correctly manage the NDN Forwarding Daemon (NFD). |
| 22 | * Inspect this object with getCause() to see why the management operation |
| 23 | * failed. |
| 24 | * |
| 25 | * @author Andrew Brown <andrew.brown@intel.com> |
| 26 | */ |
| 27 | public class ManagementException extends Exception { |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 28 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 29 | * Constructor from the message. |
| 30 | * @param message Error message |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 31 | */ |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 32 | public ManagementException(final String message) { |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 33 | super(message); |
| 34 | } |
| 35 | |
| 36 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 37 | * Constructor from the message and the cause. |
| 38 | * @param message Error message |
| 39 | * @param cause Chained exception |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 40 | */ |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 41 | public ManagementException(final String message, final Throwable cause) { |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 42 | super(message, cause); |
| 43 | } |
| 44 | |
| 45 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 46 | * Create exception from NFD's ControlResponse. |
| 47 | * @param response ControlResponse from which to use status code and status text |
| 48 | * @return new instance of ManagementException |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 49 | */ |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 50 | public static ManagementException fromResponse(final ControlResponse response) { |
andrewsbrown | 43b9630 | 2015-03-17 21:51:43 +0100 | [diff] [blame] | 51 | String message = "Action failed, forwarder returned: " + response.getStatusCode() + " " + response.getStatusText(); |
| 52 | return new ManagementException(message); |
| 53 | } |
| 54 | } |