ProtocolError.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.transport;
22 
23 import org.apache.qpid.transport.network.NetworkDelegate;
24 import org.apache.qpid.transport.network.NetworkEvent;
25 
26 
27 /**
28  * ProtocolError
29  *
30  @author Rafael H. Schloming
31  */
32 
33 public final class ProtocolError implements NetworkEvent, ProtocolEvent
34 {
35 
36     private int channel;
37     private final byte track;
38     private final String format;
39     private final Object[] args;
40 
41     public ProtocolError(byte track, String format, Object ... args)
42     {
43         this.track = track;
44         this.format = format;
45         this.args = args;
46     }
47 
48     public int getChannel()
49     {
50         return channel;
51     }
52 
53     public void setChannel(int channel)
54     {
55         this.channel = channel;
56     }
57 
58     public byte getEncodedTrack()
59     {
60         return track;
61     }
62 
63     public String getMessage()
64     {
65         return String.format(format, args);
66     }
67 
68     public <C> void delegate(C context, ProtocolDelegate<C> delegate)
69     {
70         delegate.error(context, this);
71     }
72 
73     public void delegate(NetworkDelegate delegate)
74     {
75         delegate.error(this);
76     }
77 
78     public String toString()
79     {
80         return String.format("protocol error: %s", getMessage());
81     }
82 
83 }