-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cat-client as optional dependency (#4414)
- Loading branch information
1 parent
1c4b38e
commit 9b1cd8f
Showing
7 changed files
with
27 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,83 +18,35 @@ | |
|
||
import com.ctrip.framework.apollo.tracer.spi.MessageProducer; | ||
import com.ctrip.framework.apollo.tracer.spi.Transaction; | ||
|
||
import java.lang.reflect.Method; | ||
import com.dianping.cat.Cat; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public class CatMessageProducer implements MessageProducer { | ||
private static Class CAT_CLASS; | ||
private static Method LOG_ERROR_WITH_CAUSE; | ||
private static Method LOG_ERROR_WITH_MESSAGE_AND_CAUSE; | ||
private static Method LOG_EVENT_WITH_TYPE_AND_NAME; | ||
private static Method LOG_EVENT_WITH_TYPE_AND_NAME_AND_STATUS_AND_NAME_VALUE_PAIRS; | ||
private static Method NEW_TRANSACTION_WITH_TYPE_AND_NAME; | ||
|
||
static { | ||
try { | ||
CAT_CLASS = Class.forName(CatNames.CAT_CLASS); | ||
LOG_ERROR_WITH_CAUSE = CAT_CLASS.getMethod(CatNames.LOG_ERROR_METHOD, Throwable.class); | ||
LOG_ERROR_WITH_MESSAGE_AND_CAUSE = CAT_CLASS.getMethod(CatNames.LOG_ERROR_METHOD, | ||
String.class, Throwable.class); | ||
LOG_EVENT_WITH_TYPE_AND_NAME = CAT_CLASS.getMethod(CatNames.LOG_EVENT_METHOD, | ||
String.class, String.class); | ||
LOG_EVENT_WITH_TYPE_AND_NAME_AND_STATUS_AND_NAME_VALUE_PAIRS = | ||
CAT_CLASS.getMethod(CatNames.LOG_EVENT_METHOD, String.class, String.class, | ||
String.class, String.class); | ||
NEW_TRANSACTION_WITH_TYPE_AND_NAME = CAT_CLASS.getMethod( | ||
CatNames.NEW_TRANSACTION_METHOD, String.class, String.class); | ||
//eager init CatTransaction | ||
CatTransaction.init(); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException("Initialize Cat message producer failed", ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void logError(Throwable cause) { | ||
try { | ||
LOG_ERROR_WITH_CAUSE.invoke(null, cause); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
Cat.logError(cause); | ||
} | ||
|
||
@Override | ||
public void logError(String message, Throwable cause) { | ||
try { | ||
LOG_ERROR_WITH_MESSAGE_AND_CAUSE.invoke(null, message, cause); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
Cat.logError(message, cause); | ||
} | ||
|
||
@Override | ||
public void logEvent(String type, String name) { | ||
try { | ||
LOG_EVENT_WITH_TYPE_AND_NAME.invoke(null, type, name); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
Cat.logEvent(type, name); | ||
} | ||
|
||
@Override | ||
public void logEvent(String type, String name, String status, String nameValuePairs) { | ||
try { | ||
LOG_EVENT_WITH_TYPE_AND_NAME_AND_STATUS_AND_NAME_VALUE_PAIRS.invoke(null, type, name, | ||
Cat.logEvent(type, name, | ||
status, nameValuePairs); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public Transaction newTransaction(String type, String name) { | ||
try { | ||
return new CatTransaction(NEW_TRANSACTION_WITH_TYPE_AND_NAME.invoke(null, type, name)); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
return new CatTransaction(Cat.newTransaction(type, name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,69 +24,30 @@ | |
* @author Jason Song([email protected]) | ||
*/ | ||
public class CatTransaction implements Transaction { | ||
private static Class CAT_TRANSACTION_CLASS; | ||
private static Method SET_STATUS_WITH_STRING; | ||
private static Method SET_STATUS_WITH_THROWABLE; | ||
private static Method ADD_DATA_WITH_KEY_AND_VALUE; | ||
private static Method COMPLETE; | ||
|
||
private Object catTransaction; | ||
private com.dianping.cat.message.Transaction catTransaction; | ||
|
||
static { | ||
try { | ||
CAT_TRANSACTION_CLASS = Class.forName(CatNames.CAT_TRANSACTION_CLASS); | ||
SET_STATUS_WITH_STRING = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD, String.class); | ||
SET_STATUS_WITH_THROWABLE = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD, | ||
Throwable.class); | ||
ADD_DATA_WITH_KEY_AND_VALUE = CAT_TRANSACTION_CLASS.getMethod(CatNames.ADD_DATA_METHOD, | ||
String.class, Object.class); | ||
COMPLETE = CAT_TRANSACTION_CLASS.getMethod(CatNames.COMPLETE_METHOD); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException("Initialize Cat transaction failed", ex); | ||
} | ||
} | ||
|
||
static void init() { | ||
//do nothing, just to initialize the static variables | ||
} | ||
|
||
public CatTransaction(Object catTransaction) { | ||
public CatTransaction(com.dianping.cat.message.Transaction catTransaction) { | ||
this.catTransaction = catTransaction; | ||
} | ||
|
||
@Override | ||
public void setStatus(String status) { | ||
try { | ||
SET_STATUS_WITH_STRING.invoke(catTransaction, status); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
catTransaction.setStatus(status); | ||
} | ||
|
||
@Override | ||
public void setStatus(Throwable status) { | ||
try { | ||
SET_STATUS_WITH_THROWABLE.invoke(catTransaction, status); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
catTransaction.setStatus(status); | ||
} | ||
|
||
@Override | ||
public void addData(String key, Object value) { | ||
try { | ||
ADD_DATA_WITH_KEY_AND_VALUE.invoke(catTransaction, key, value); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
catTransaction.addData(key, value); | ||
} | ||
|
||
@Override | ||
public void complete() { | ||
try { | ||
COMPLETE.invoke(catTransaction); | ||
} catch (Throwable ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
catTransaction.complete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters