io.vertx.core.dns.impl.netty.DnsMessage Maven / Gradle / Ivy
/*
* Copyright (c) 2013 The Netty Project
* ------------------------------------
* 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 io.vertx.core.dns.impl.netty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The message super-class which contains core information concerning DNS
* packets, both outgoing and incoming.
*/
public abstract class DnsMessage {
private final List questions = new ArrayList<>();
private final List answers = new ArrayList<>();
private final List authority = new ArrayList<>();
private final List additional = new ArrayList<>();
private H header;
/**
* Returns the header belonging to this message.
*/
public H getHeader() {
return header;
}
/**
* Returns a list of all the questions in this message.
*/
public List getQuestions() {
return Collections.unmodifiableList(questions);
}
/**
* Returns a list of all the answer resource records in this message.
*/
public List getAnswers() {
return Collections.unmodifiableList(answers);
}
/**
* Returns a list of all the authority resource records in this message.
*/
public List getAuthorityResources() {
return Collections.unmodifiableList(authority);
}
/**
* Returns a list of all the additional resource records in this message.
*/
public List getAdditionalResources() {
return Collections.unmodifiableList(additional);
}
/**
* Adds an answer resource record to this message.
*
* @param answer the answer resource record to be added
* @return the message to allow method chaining
*/
public DnsMessage addAnswer(DnsResource answer) {
answers.add(answer);
return this;
}
/**
* Adds a question to this message.
*
* @param question the question to be added
* @return the message to allow method chaining
*/
public DnsMessage addQuestion(DnsQuestion question) {
questions.add(question);
return this;
}
/**
* Adds an authority resource record to this message.
*
* @param resource the authority resource record to be added
* @return the message to allow method chaining
*/
public DnsMessage addAuthorityResource(DnsResource resource) {
authority.add(resource);
return this;
}
/**
* Adds an additional resource record to this message.
*
* @param resource the additional resource record to be added
* @return the message to allow method chaining
*/
public DnsMessage addAdditionalResource(DnsResource resource) {
additional.add(resource);
return this;
}
/**
* Sets this message's {@link DnsHeader}.
*
* @param header the header being attached to this message
* @return the message to allow method chaining
*/
public DnsMessage setHeader(H header) {
this.header = header;
return this;
}
}