All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.websocket.ClientEndpointConfigurationBuilder Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javax.websocket;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The ClientEndpointConfigurationBuilder is a class used for creating
 * {@link ClientEndpointConfiguration} objects for the purposes of
 * deploying a client endpoint.
 * 

Here are some examples:
*
Building a plain configuration with no encoders, decoders, subprotocols or extensions.

* * ClientEndpointConfiguration cec = ClientEndpointConfigurationBuilder.create().build();
*
* *

Building a configuration with no subprotocols and a custom configurator.

* * ClientEndpointConfiguration customCec = ClientEndpointConfigurationBuilder.create()
*    .preferredSubprotocols(mySubprotocols)
*    .clientHandshakeConfigurator(new MyClientConfigurator())
*    .build();
*
* * * @author dannycoward */ public class ClientEndpointConfigurationBuilder { private List preferredSubprotocols = new ArrayList(); private List extensions = new ArrayList(); private List encoders = new ArrayList(); private List decoders = new ArrayList(); private ClientEndpointConfigurator clientEndpointConfigurator = new ClientEndpointConfigurator() { }; /** * Creates a new builder object with no subprotocols, extensions, encoders, * decoders and a null configurator. * * @return a new builder object. */ public static ClientEndpointConfigurationBuilder create() { return new ClientEndpointConfigurationBuilder(); } /** * Builds a configuration object using the attributes set * on this builder. * * @return a new configuration object. */ public ClientEndpointConfiguration build() { return new DefaultClientEndpointConfiguration( Collections.unmodifiableList(this.preferredSubprotocols), Collections.unmodifiableList(this.extensions), Collections.unmodifiableList(this.encoders), Collections.unmodifiableList(this.decoders), this.clientEndpointConfigurator); } /** * Sets the configurator object for the configuration this builder will build. * * @param clientEndpointConfigurator the configurator * @return the builder instance */ public ClientEndpointConfigurationBuilder clientHandshakeConfigurator(ClientEndpointConfigurator clientEndpointConfigurator) { this.clientEndpointConfigurator = clientEndpointConfigurator; return this; } /** * Set the preferred sub protocols for the configuration this builder will build. The * list is treated in order of preference, favorite first, that this client would * like to use for its sessions. * * @param preferredSubprotocols the preferred subprotocol names. * @return the builder instance */ public ClientEndpointConfigurationBuilder preferredSubprotocols(List preferredSubprotocols) { this.preferredSubprotocols = (preferredSubprotocols == null) ? new ArrayList() : preferredSubprotocols; return this; } /** * Set the extensions for the configuration this builder will build. The * list is treated in order of preference, favorite first, that the * client would like to use for its sessions. * * @param extensions the extensions * @return the builder instance */ public ClientEndpointConfigurationBuilder extensions(List extensions) { this.extensions = (extensions == null) ? new ArrayList() : extensions; return this; } /** * Assign the list of encoders the client will use. * * @param encoders the encoders * @return the builder instance */ public ClientEndpointConfigurationBuilder encoders(List encoders) { this.encoders = (encoders == null) ? new ArrayList() : encoders; return this; } /** * Assign the list of decoders the client will use. * * @param decoders the decoders * @return this builder instance */ public ClientEndpointConfigurationBuilder decoders(List decoders) { this.decoders = (decoders == null) ? new ArrayList() : decoders; return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy