com.signalfx.shaded.jetty.client.ProtocolHandlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signalfx-codahale Show documentation
Show all versions of signalfx-codahale Show documentation
Dropwizard Codahale metrics plugin for signalfx
The newest version!
//
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package com.signalfx.shaded.jetty.client;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import com.signalfx.shaded.jetty.client.api.Request;
import com.signalfx.shaded.jetty.client.api.Response;
import com.signalfx.shaded.jetty.util.component.Dumpable;
/**
* A container for {@link ProtocolHandler}s accessible from {@link HttpClient#getProtocolHandlers()}.
*/
public class ProtocolHandlers implements Dumpable
{
private final Map handlers = new LinkedHashMap<>();
protected ProtocolHandlers()
{
}
/**
* Stores the given {@code protocolHandler} in this container.
* If a protocol handler with the same name exists, it is
* replaced by the given one, and the existing returned.
*
* @param protocolHandler the protocol handler to store
* @return the existing protocol handler with the same name,
* or null if no protocol handler with that name was already stored
* @see #remove(String)
*/
public ProtocolHandler put(ProtocolHandler protocolHandler)
{
return handlers.put(protocolHandler.getName(), protocolHandler);
}
/**
* Removes the protocol handler with the given name.
*
* @param name the name of the protocol handler to remove
* @return the removed protocol handler, or null if no
* protocol handler with that name was already stored
* @see #put(ProtocolHandler)
* @see #clear()
*/
public ProtocolHandler remove(String name)
{
return handlers.remove(name);
}
/**
* Removes all protocol handlers from this container.
*/
public void clear()
{
handlers.clear();
}
/**
* Finds the first protocol handler that
* {@link ProtocolHandler#accept(Request, Response) accepts}
* the given request and response.
*
* @param request the request to accept
* @param response the response to accept
* @return the protocol handler that accepted the request and response,
* or null if none of the protocol handlers accepted the request and response
*/
public ProtocolHandler find(Request request, Response response)
{
for (ProtocolHandler handler : handlers.values())
{
if (handler.accept(request, response))
return handler;
}
return null;
}
@Override
public String dump()
{
return Dumpable.dump(this);
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
Dumpable.dumpObjects(out, indent, this, handlers);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy