class SpacewalkService {

    @SuppressWarnings("unchecked")
    public static List<SpacewalkChannel> getChannels(final Credentials credentials,
            final URL spacewalkBaseUrl) throws SpacewalkException {

        validateParameters(credentials, spacewalkBaseUrl);
        URL queryUrl = getQueryUrl(spacewalkBaseUrl);
        Object sessionKey = getSessionKey(credentials, queryUrl);
        XmlRpcClient client = createXmlRpcClient(queryUrl);

        List<SpacewalkChannel> channelList = new ArrayList<>();
        try {
            Object[] rawChannels =
                    (Object[]) client.execute("channel.listAllChannels", new Object[] {sessionKey});

            for (Object channelObj : rawChannels) {
                Map<String, Object> channelMap = (Map<String, Object>) channelObj;

                SpacewalkChannel channel = new SpacewalkChannel(channelMap, spacewalkBaseUrl);
                channelList.add(channel);
            }
            LOGGER.info("Found " + rawChannels.length + " channels. Closing session");
            closeSession(sessionKey, queryUrl);
        } catch (XmlRpcException e) {
            String message = "Error getting list of spacewalk channels: " + e.getMessage();
            LOGGER.error(message, e);
            throw new SpacewalkException(message, e);
        } catch (IllegalArgumentException iae) {
            String message = "Error processing channel map returned from Spacewalk";
            LOGGER.error(message, iae);
            throw new SpacewalkException(message, iae);
        } finally {
            closeSession(sessionKey, queryUrl);
        }
        return channelList;
    }

    private  SpacewalkService();

}