我想实现以下目标:
在事务内部,我想生成多个日志消息.只有在成功提交事务时才应写入这些日志消息.如果事务回滚,则不得记录日志消息.
我找不到任何东西来实现这个(使用spring,hibernate,atomikos),所以我写了这个小包装器(我遗漏了几个方便方法):
public class TransactionLogger {
private Logger logger;
private Map<Long, LinkedList<LogRecord>> threadBuffers =
new HashMap<Long, LinkedList<LogRecord>>();
public TransactionLogger(Logger logger) {
this.logger = logger;
}
private void addRecord(LogRecord rec) {
LinkedList<LogRecord> list =
threadBuffers.get(Thread.currentThread().getId());
if (list == null) {
list = new LinkedList<LogRecord>();
threadBuffers.put(Thread.currentThread().getId(), list);
}
list.add(rec);
}
private LinkedList<LogRecord> getRecords() {
if (threadBuffers.containsKey(Thread.currentThread().getId())) {
return threadBuffers.remove(Thread.currentThread().getId());
} else {
return new LinkedList<LogRecord>();
}
}
public void commit() {
for (LogRecord rec : getRecords()) {
rec.setLoggerName(logger.getName());
logger.log(rec);
}
} …
Run Code Online (Sandbox Code Playgroud) 我的设备管理器中列出了以下串口:
所述SUNIX COM端口经由内部PCI卡连接.的USB串行端口通过USB(FDTI芯片)的连接GLOBETROTTER端口是从经由USB连接的设备周游世界.此调制解调器还有一个调制解调器,一个USB设备和一个网络设备.
所以我有几个不同的串口来源.
我想要做的就是使用WMI获取包含所有端口的列表.
对于我的测试,我使用的是WMI Code Creator
测试1:
root\CIMV2
; 查询:SELECT * FROM Win32_SerialPort
仅返回以下串口:
测试2:
root\WMI
; 查询:SELECT * FROM MSSerial_PortName
仅返回以下串口:
如何获得完整的串口列表?
我想在我的xamarin应用程序中实现客户端证书身份验证.最重要的是,我使用自定义证书颁发机构(CA)和TLS 1.2.
到目前为止,我设法使用android,UWP和WPF运行它.唯一缺少的平台是ios.
这是我的NSUrlSessionDelegate:
public class SSLSessionDelegate : NSUrlSessionDelegate, INSUrlSessionDelegate
{
private NSUrlCredential Credential { get; set; }
private SecIdentity identity = null;
private X509Certificate2 ClientCertificate = null;
private readonly SecCertificate CACertificate = null;
public SSLSessionDelegate(byte[] caCert) : base()
{
if (caCert != null)
{
CACertificate = new SecCertificate(new X509Certificate2(caCert));
}
}
public void SetClientCertificate(byte[] pkcs12, char[] password)
{
if (pkcs12 != null)
{
ClientCertificate = new X509Certificate2(pkcs12, new string(password));
identity = SecIdentity.Import(ClientCertificate);
SecCertificate certificate = new SecCertificate(ClientCertificate);
SecCertificate[] certificates …
Run Code Online (Sandbox Code Playgroud) 我有一个已经在JavaSE上工作的自定义字符集.
我的CharsetProvider的类在一个文件java.nio.charset.spi.CharsetProvider
中指定,该文件位于META-INF/services
并且所有内容都正常加载并按预期工作.
但是现在我也在android上使用lib,但是在Android-App中没有加载charset.
如何集成我的charset,以便在Android-App中使用它?
Charset.forName("MyCS");
Run Code Online (Sandbox Code Playgroud)
目前我正在做一个像这样的解决方法:
public static String decode(String encoding, byte[] buffer, int offset, int length) {
String result = "";
try {
result = new String(buffer, offset, length, encoding);
} catch (UnsupportedEncodingException ex) {
MyCharsetProvider provider = new MyCharsetProvider();
Charset cs = provider.charsetForName(encoding);
if (cs == null) {
Logger.getLogger(Converters.class.getName()).log(
Level.SEVERE,null,ex);
result = new String(buffer, offset, length);
} else {
result = cs.decode(ByteBuffer.wrap(buffer, offset, length)).toString();
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
哪个有效,但对我来说似乎无效,因为每次我尝试使用自己的字符集进行解码时,都会抛出异常并创建一个CharsetProvider-Object.
单一模式可以减少课程的创建.但问题是避免完全直接使用MyCharsetProvider.
编辑:
由于META-INF/services/java.nio.charset.spi.CharsetProvider …
我使用的是 Spring 3.0.5、Hibernate 3.6.7 和 Atomikos Transactionessentials 3.7.0。使用 applicationContext.xml 中的 AOP 配置的事务。一切正常。(提交,回滚)
我的目的是在 jta 事务中抛出一个特定的异常。通过这种方式,事务应该被回滚,我会得到一些关于回滚原因的详细信息。
问题是,我能捕获的唯一异常是 atomikos 抛出的回滚事务,告诉我事务意外回滚。
如何在事务之外获得自己的异常?
这是一个小例子,因为我不知道我的解释是否足够好。这只是为了说明我的意图。请不要评论任何错别字。
一个特定的例外(也可能是一些标准例外):
public class MySpecialException extends Exception {
public MySpecialException(String someInfo) {
super(someInfo);
}
}
Run Code Online (Sandbox Code Playgroud)
声明一个声明抛出异常的方法的接口:
public interface MyInterface {
Object someJtaTransactionMethod(String param) throws MySpecialException;
}
Run Code Online (Sandbox Code Playgroud)
实现接口的类:
public class MyClass implements MyInterface {
Object someJtaTransactionMethod(String param) throws MySpecialException {
// some operations with some errorstate detected
// so throw the exception:
throw new MySpecialException("Things went terribly wrong!");
// some other code …
Run Code Online (Sandbox Code Playgroud) 我在VS2010中使用Robert Giesecke Unmanaged Exports 1.2.6,我的目标是将一系列结构从c#(.NET 3.5)传递给delphi(D7).我不得不承认,我对德尔福并不熟悉.
我已经阅读过这篇文章,但建议的答案对我不起作用:当func
在delphi中调用时,CPU调试窗口打开,如果我继续应用程序退出,无异常且没有所需的结果.
这是我试过的代码:
C#平台x86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
namespace ArrayTest
{
public class Class1
{
public struct Sample
{
[MarshalAs(UnmanagedType.BStr)]
public string Name;
}
[DllExport]
public static int func(
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]
Sample[] samples,
ref int len
)
{
// len holds the length of the array on input
// len is assigned the …
Run Code Online (Sandbox Code Playgroud) 我想知道在Android上使用ORM的真正必要性.什么是" 加号 "认为,使用ORM在Android conding时,可我们得到的?是不是使用本机android方法sufficiant(使用SqlLIte和编写自己的类和自己的SQL查询(我认为需要大量的时间和代码行))?
使用ORM尤其是在移动设备上有什么好处和缺点?
我编写了使用 AT 命令识别和控制不同调制解调器的软件。
一切正常,但我想知道调制解调器是否支持 GPRS、Edge、3G 或 LTE。
我怎样才能得到这些信息?
它是由调制解调器通过主动提供的结果提供的,还是我必须使用特定的标准命令(或调制解调器相关命令)来查询信息?
我想要一个通用的解决方案,但这不可能作为对我的调制解调器 (GTM661W)的[AcT]
响应+CREG
并且+CGREG
不会返回,无论我是否连接。
所以我用专有命令效力于GTM661W和管理,以获取有关信息WCDMA
-status(如WCDMA
,WCDMA + HSDPA
,WCDMA + HSUPA
或WCDMA + HSDPA + HSUPA
使用)unsing _OWCTI?
。
我尝试了以下命令:
_OWCTI?
=> _OWCTI: 4
_OUWCTI?
=> _OUWCTI: 0,4
_OCTI?
=> _OCTI: 0,0
这意味着现在我能够识别3G
和H
连接类型,但不能识别G
和E
。
我如何识别G
, E
,3G
和H
?
不幸的是,我无法再对此进行测试。因此,我无法接受答案,因为我无法评估这些解决方案是否适用于不同制造商的各种设备。
出于某种原因,我的单例存储库是从后台线程多次创建的,但是,synchronized应该有帮助.有人可以帮忙吗?如果需要,我将提供代码片段和github链接.
我的IntentService类:
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.d(MainActivity.TAG, "ArticleIntentService - onHandleIntent");
LiveData<List<Article>> liveArticles = ArticleRepository.getInstance(getApplication())
.loadFromNetwork(PAGE_NUMBER, PAGE_SIZE);
PAGE_NUMBER++;
liveArticles.observeForever(articles -> {
Log.d(MainActivity.TAG, "onStartJob - onChanged!!!!!!");
// liveArticles.removeObserver(this);
NotificationUtils.showNotification(context, articles.get(0).getSectionName(), articles.get(0).getWebTitle());
});
}
Run Code Online (Sandbox Code Playgroud)
我的存储库:
public static ArticleRepository INSTANCE;
public static synchronized ArticleRepository getInstance(Application application){
if(INSTANCE == null){
Log.d(TAG, "ArticleRepository getInstance is NULL");
return new ArticleRepository(application);
}
return INSTANCE;
}
private ArticleRepository(Application application) {
Log.d(TAG, "ArticleRepository constructor");
mContext = application;
mArticles = new MutableLiveData<>();
ArticleRoomDatabase db = ArticleRoomDatabase.getInstance(application);
mArticleDao = …
Run Code Online (Sandbox Code Playgroud)