use of org.apache.thrift.protocol.TProtocolException in project pinpoint by naver.
the class ThriftRequestProperty method writeTraceHeader.
public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
Object headerValue = this.thriftHeaders.get(headerKey);
if (headerValue == null) {
return;
}
byte headerType = headerKey.getType();
TField traceField = new TField(headerKey.name(), headerKey.getType(), headerKey.getId());
oprot.writeFieldBegin(traceField);
try {
if (headerType == TType.STRING) {
// these will be read as byte buffer although it's probably safe to just use writeString here.
// see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
oprot.writeBinary(stringToByteBuffer((String) headerValue));
} else if (headerType == TType.I64) {
oprot.writeI64((Long) headerValue);
} else if (headerType == TType.I16) {
oprot.writeI16((Short) headerValue);
} else if (headerType == TType.BOOL) {
oprot.writeBool((Boolean) headerValue);
} else {
throw new TProtocolException("Invalid pinpoint header type - " + headerType);
}
} finally {
oprot.writeFieldEnd();
}
}
use of org.apache.thrift.protocol.TProtocolException in project hive by apache.
the class RetryingMetaStoreClient method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object ret;
int retriesMade = 0;
TException caughtException;
boolean allowReconnect = !method.isAnnotationPresent(NoReconnect.class);
boolean allowRetry = true;
Annotation[] directives = method.getDeclaredAnnotations();
if (directives != null) {
for (Annotation a : directives) {
if (a instanceof RetrySemantics.CannotRetry) {
allowRetry = false;
}
}
}
while (true) {
try {
reloginExpiringKeytabUser();
if (allowReconnect) {
if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) {
if (this.ugi != null) {
// Perform reconnect with the proper user context
try {
LOG.info("RetryingMetaStoreClient trying reconnect as " + this.ugi);
this.ugi.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws MetaException {
base.reconnect();
return null;
}
});
} catch (UndeclaredThrowableException e) {
Throwable te = e.getCause();
if (te instanceof PrivilegedActionException) {
throw te.getCause();
} else {
throw te;
}
}
lastConnectionTime = System.currentTimeMillis();
} else {
LOG.warn("RetryingMetaStoreClient unable to reconnect. No UGI information.");
throw new MetaException("UGI information unavailable. Will not attempt a reconnect.");
}
}
}
if (metaCallTimeMap == null) {
ret = method.invoke(base, args);
} else {
// need to capture the timing
long startTime = System.currentTimeMillis();
ret = method.invoke(base, args);
long timeTaken = System.currentTimeMillis() - startTime;
addMethodTime(method, timeTaken);
}
break;
} catch (UndeclaredThrowableException e) {
throw e.getCause();
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof TApplicationException) {
TApplicationException tae = (TApplicationException) t;
switch(tae.getType()) {
case TApplicationException.UNSUPPORTED_CLIENT_TYPE:
case TApplicationException.UNKNOWN_METHOD:
case TApplicationException.WRONG_METHOD_NAME:
case TApplicationException.INVALID_PROTOCOL:
throw t;
default:
// TODO: most other options are probably unrecoverable... throw?
caughtException = tae;
}
} else if ((t instanceof TProtocolException) || (t instanceof TTransportException)) {
// TODO: most protocol exceptions are probably unrecoverable... throw?
caughtException = (TException) t;
} else if ((t instanceof MetaException) && t.getMessage().matches("(?s).*(JDO[a-zA-Z]*|TProtocol|TTransport)Exception.*") && !t.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
caughtException = (MetaException) t;
} else {
throw t;
}
} catch (MetaException e) {
if (e.getMessage().matches("(?s).*(IO|TTransport)Exception.*") && !e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
caughtException = e;
} else {
throw e;
}
}
if (retriesMade >= retryLimit || base.isLocalMetaStore() || !allowRetry) {
throw caughtException;
}
retriesMade++;
LOG.warn("MetaStoreClient lost connection. Attempting to reconnect (" + retriesMade + " of " + retryLimit + ") after " + retryDelaySeconds + "s. " + method.getName(), caughtException);
Thread.sleep(retryDelaySeconds * 1000);
}
return ret;
}
use of org.apache.thrift.protocol.TProtocolException in project storm by apache.
the class ComponentObject method tupleSchemeReadValue.
@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
_Fields setField = _Fields.findByThriftId(fieldID);
if (setField != null) {
switch(setField) {
case SERIALIZED_JAVA:
ByteBuffer serialized_java;
serialized_java = iprot.readBinary();
return serialized_java;
case SHELL:
ShellComponent shell;
shell = new ShellComponent();
shell.read(iprot);
return shell;
case JAVA_OBJECT:
JavaObject java_object;
java_object = new JavaObject();
java_object.read(iprot);
return java_object;
default:
throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
}
} else {
throw new TProtocolException("Couldn't find a field with field id " + fieldID);
}
}
use of org.apache.thrift.protocol.TProtocolException in project storm by apache.
the class HBMessageData method tupleSchemeReadValue.
@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
_Fields setField = _Fields.findByThriftId(fieldID);
if (setField != null) {
switch(setField) {
case PATH:
String path;
path = iprot.readString();
return path;
case PULSE:
HBPulse pulse;
pulse = new HBPulse();
pulse.read(iprot);
return pulse;
case BOOLVAL:
Boolean boolval;
boolval = iprot.readBool();
return boolval;
case RECORDS:
HBRecords records;
records = new HBRecords();
records.read(iprot);
return records;
case NODES:
HBNodes nodes;
nodes = new HBNodes();
nodes.read(iprot);
return nodes;
case MESSAGE_BLOB:
ByteBuffer message_blob;
message_blob = iprot.readBinary();
return message_blob;
default:
throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
}
} else {
throw new TProtocolException("Couldn't find a field with field id " + fieldID);
}
}
use of org.apache.thrift.protocol.TProtocolException in project jstorm by alibaba.
the class Grouping method tupleSchemeReadValue.
@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
_Fields setField = _Fields.findByThriftId(fieldID);
if (setField != null) {
switch(setField) {
case FIELDS:
List<String> fields;
{
org.apache.thrift.protocol.TList _list12 = iprot.readListBegin();
fields = new ArrayList<String>(_list12.size);
String _elem13;
for (int _i14 = 0; _i14 < _list12.size; ++_i14) {
_elem13 = iprot.readString();
fields.add(_elem13);
}
iprot.readListEnd();
}
return fields;
case SHUFFLE:
NullStruct shuffle;
shuffle = new NullStruct();
shuffle.read(iprot);
return shuffle;
case ALL:
NullStruct all;
all = new NullStruct();
all.read(iprot);
return all;
case NONE:
NullStruct none;
none = new NullStruct();
none.read(iprot);
return none;
case DIRECT:
NullStruct direct;
direct = new NullStruct();
direct.read(iprot);
return direct;
case CUSTOM_OBJECT:
JavaObject custom_object;
custom_object = new JavaObject();
custom_object.read(iprot);
return custom_object;
case CUSTOM_SERIALIZED:
ByteBuffer custom_serialized;
custom_serialized = iprot.readBinary();
return custom_serialized;
case LOCAL_OR_SHUFFLE:
NullStruct local_or_shuffle;
local_or_shuffle = new NullStruct();
local_or_shuffle.read(iprot);
return local_or_shuffle;
case LOCAL_FIRST:
NullStruct localFirst;
localFirst = new NullStruct();
localFirst.read(iprot);
return localFirst;
default:
throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
}
} else {
throw new TProtocolException("Couldn't find a field with field id " + fieldID);
}
}
Aggregations