org.atmosphere.stomp.protocol.Frame Maven / Gradle / Ivy
/*
* Copyright 2014 Jeanfrancois Arcand
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.stomp.protocol;
import java.util.Collections;
import java.util.Map;
/**
*
* In STOMP protocol, the frame basically defines an {@link Action}, some {@link Header headers} and eventually a body.
*
*
*
* A frame is immutable.
*
*
* @author Guillaume DROUET
* @since 0.1
* @version 1.0
*/
public final class Frame {
/**
* The action.
*/
private final Action action;
/**
* The body.
*/
private final String body;
/**
* The headers.
*/
private final Map headers;
/**
*
* Builds a new instance.
*
*
* @param action the action
* @param headers the headers
* @param body the body
*/
public Frame(final Action action, final Map headers, final String body) {
this.action = action;
this.body = body;
headers.put(Header.CONTENT_LENGTH, String.valueOf(body == null ? 0 : body.getBytes().length));
this.headers = Collections.unmodifiableMap(headers);
}
/**
*
* Builds a new instance without body.
*
*
* @param action the action
* @param headers the headers
*/
public Frame(final Action action, final Map headers) {
this(action, headers, null);
}
/**
*
* Gets the action.
*
*
* @return the action
*/
public Action getAction() {
return action;
}
/**
*
* Gets the body.
*
*
* @return the body
*/
public String getBody() {
return body;
}
/**
*
* Gets the headers.
*
*
* @return the headers
*/
public Map getHeaders() {
return headers;
}
}