001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.protocol.request;
019
020 import org.otfeed.event.ICompletionDelegate;
021 import org.otfeed.protocol.CommandEnum;
022
023 import java.nio.ByteBuffer;
024
025 /**
026 * Common base for all OpenTick session requests. Note that only
027 * {@link LoginRequest} does not have session context, and therefore
028 * is not derived from this class. All other requests are session requests.
029 */
030 public abstract class AbstractSessionRequest extends AbstractRequest {
031
032 private String sessionId = "";
033
034 /**
035 * Gets session id string.
036 * @return session id string.
037 */
038 public String getSessionId() { return sessionId; }
039
040 /**
041 * Sets session id string.
042 * @param val session id string.
043 */
044 public void setSessionId(String val) { sessionId = val; }
045
046 AbstractSessionRequest(CommandEnum command,
047 int requestId,
048 ICompletionDelegate completionDelegate) {
049 super(command, requestId, completionDelegate);
050 }
051
052 /**
053 * Writes out the request header and session string.
054 * Subclasses must override this if needed, and their
055 * implementation must call this method as the first operation.
056 */
057 @Override
058 public void writeRequest(ByteBuffer out) {
059 super.writeRequest(out);
060 Util.writeString(out, sessionId, 64);
061 }
062
063 /**
064 * Returns cancel command type.
065 * Some requests can be cancelled by sending a {@link CancelRequest}
066 * to the server. Such requests must override this method
067 * to return the cancel command type.
068 */
069 public CommandEnum getCancelCommand() {
070 return null;
071 }
072 }