net.sf.eBus.client.sysmessages.ResumeReply Maven / Gradle / Ivy
The newest version!
//
// Copyright 2019, 2020 Charles W. Rapp
//
// 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 net.sf.eBus.client.sysmessages;
import java.io.Serializable;
import javax.annotation.Nullable;
import net.sf.eBus.messages.EReplyMessage.ReplyStatus;
import net.sf.eBus.util.Validator;
/**
* Response to a connection resume request. The reply status is
* {@link ReplyStatus#OK_FINAL} when the request is accepted and
* {@link ReplyStatus#ERROR} when rejected. If rejected, then
* {@link #replyReason} contains text explaining the rejection.
*
* @author Charles W. Rapp
*/
public final class ResumeReply
extends AbstractLogonMessage
implements Serializable
{
//---------------------------------------------------------------
// Member data.
//
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x050200L;
//-----------------------------------------------------------
// Locals.
//
/**
* The current request handling status. If
* {@link ReplyStatus#ERROR}, then {@link #replyReason} will
* contain text explaining why the request was rejected.
*/
public final ReplyStatus replyStatus;
/**
* The reason for a {@link ReplyStatus#ERROR} reply status.
* May be {@code null} or empty.
*/
@Nullable
public final String replyReason;
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a resume reply message from the given message
* configuration.
* @param builder resume reply message builder.
*/
private ResumeReply(final Builder builder)
{
super (builder);
this.replyStatus = builder.mReplyStatus;
this.replyReason = builder.mReplyReason;
} // end of ResumeReply(Builder)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
@Override
public String toString()
{
return (
String.format(
"%s%n status: %s%n reason: %s",
super.toString(),
replyStatus,
replyReason));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
/**
* Returns a new instance of the {@code ResumeReply} message
* builder.
* @return message builder instance.
*/
public static Builder builder()
{
return (new Builder());
} // end of builder()
//---------------------------------------------------------------
// Inner classes.
//
/**
* Class used to create {@link ResumeReply} messages. Used
* by eBus to de-serialize an encoded message.
*/
public static final class Builder
extends AbstractLogonMessage.Builder
{
//-----------------------------------------------------------
// Member data.
//
//-------------------------------------------------------
// Locals.
//
/**
* The current request handling status. If
* {@link ReplyStatus#ERROR}, then {@link #replyReason}
* will contain text explaining why the request was
* rejected.
*/
private ReplyStatus mReplyStatus;
/**
* The reason for a {@link ReplyStatus#ERROR} reply status.
* May be {@code null} or empty.
*/
private String mReplyReason;
//-----------------------------------------------------------
// Member methods.
//
//-------------------------------------------------------
// Constructors.
//
private Builder()
{
super (ResumeReply.class);
} // end of Builder()
//
// end of Constructors.
//-------------------------------------------------------
//-------------------------------------------------------
// Builder Method Overrides.
//
/**
* Returns the newly instantiated {@code ResumeReply}
* message based on this builder configuration.
* @return target message instance.
*/
@Override
protected ResumeReply buildImpl()
{
return (new ResumeReply(this));
} // end of buildImpl()
/**
* Adds any and all configuration problems to
* {@code problems}.
* @param problems used to check field validity and
* collect discovered invalid fields.
* @return {@code problems} to allow for method chaining.
*/
@Override
protected Validator validate(final Validator problems)
{
// Only reply status must be set.
return (super.validate(problems)
.requireNotNull(mReplyStatus,
"reply status"));
} // end of validate(Validator)
//
// end of Builder Method Overrides.
//-------------------------------------------------------
//-------------------------------------------------------
// Set Methods.
//
/**
* Sets the reply status to the given value.
* @param status reply status.
* @return {@code this} resume reply builder.
* @throws NullPointerException
* if {@code status} is {@code null}.
*/
public Builder replyStatus(final ReplyStatus status)
{
if (status == null)
{
throw (
new NullPointerException("status is null"));
}
mReplyStatus = status;
return (this);
} // end of replyStatus(ReplyStatus)
/**
* Sets the reply reason to the given value. May be
* {@code null} or an empty string.
* @param reason reply reason.
* @return {@code this} resume reply builder.
*/
public Builder replyReason(final String reason)
{
mReplyReason = reason;
return (this);
} // end of replyReason(String)
//
// end of Set Methods.
//-------------------------------------------------------
} // end of class Builder
} // end of class ResumeReply