小编hal*_*lil的帖子

如何在kafka中找到分配给主题的哪个分区的消费者?

我正在构建一个kafka manager tool,我需要检查哪个主题分区被分配给一个消费者组中的哪个消费者.

假设有消费群group-A消费的话题topic-An partitions,所以可以有多个消费者group-A的托管different VM's.那么如何找到哪个分区被分配给哪个消费者主机?有可能kafka 0.9.1吗?

提前致谢.

java apache-kafka kafka-consumer-api apache-zookeeper

7
推荐指数
1
解决办法
2475
查看次数

WatchService有时会触发ENTRY_MODIFY两次,有时一次

我在WatchServiceOracle中使用这个例子:

import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
import static java.nio.file.LinkOption.*;
import java.nio.file.attribute.*;
import java.io.*;
import java.util.*;

public class WatchDir {

private final WatchService watcher;
private final Map<WatchKey,Path> keys;
private final boolean recursive;
private boolean trace = false;

@SuppressWarnings("unchecked")
static <T> WatchEvent<T> cast(WatchEvent<?> event) {
    return (WatchEvent<T>)event;
}

/**
 * Register the given directory with the WatchService
 */
private void register(Path dir) throws IOException {
    WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    if (trace) {
        Path prev = keys.get(key);
        if …
Run Code Online (Sandbox Code Playgroud)

java rhel watchservice nio2

6
推荐指数
1
解决办法
2502
查看次数

降低切换语句的循环复杂度-Sonar

我想减少开关情况的圈复杂度,我的代码是:

public String getCalenderName() {
        switch (type) {
    case COUNTRY:
        return country == null ? name : country.getName() + HOLIDAY_CALENDAR;
    case CCP:
        return ccp == null ? name : ccp.getName() + " CCP" + HOLIDAY_CALENDAR;
    case EXCHANGE:
        return exchange == null ? name : exchange.getName() + HOLIDAY_CALENDAR;
    case TENANT:
        return tenant == null ? name : tenant.getName() + HOLIDAY_CALENDAR;
    default:
        return name;
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码块的复杂度为16,并希望将其降低到10。country,ccp,exchange和tenant是我的不同对象。基于类型I将调用它们各自的方法。

java cyclomatic-complexity switch-statement sonarqube

6
推荐指数
2
解决办法
9884
查看次数

如何解决像java.lang.Throwable:setStateLocked这样的错误?

我正在开发一个应用程序.在其中我使用listview.当我点击列表项时,它应该转到下一个活动,即ProfileActivity2.java.它工作正常,但在这个ProfileActivty2底部有一个按钮,当我点击这个按钮时,我的应用程序崩溃并停在listview页面中.并在listview布局文件中显示错误java.lang.Throwable:setStateLocked,即atSetContentView.我该如何解决这个错误?

//ProfileActivity2.java

    public class ProfileActivity2 extends AppCompatActivity {

        //Textview to show currently logged in user
        private TextView textView;
        private boolean loggedIn = false;
        Button btn;
        EditText edname,edaddress;

        TextView tvsname, tvsprice;
        NumberPicker numberPicker;
        TextView textview1,textview2;
        Integer temp;
        String pname, paddress, email, sname, sprice;


        @Override
        protected void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_profile1);

            //Initializing textview
            textView = (TextView) findViewById(R.id.textView);
            edname=(EditText)findViewById(R.id.ed_pname);
            edaddress=(EditText)findViewById(R.id.ed_add);
            tvsname=(TextView)findViewById(R.id.textView_name);
            tvsprice=(TextView)findViewById(R.id.textView2_price);
            btn=(Button)findViewById(R.id.button);

            Intent i = getIntent();
            // getting attached intent data
            String name = i.getStringExtra("sname");
            // displaying selected product name
            tvsname.setText(name);

            String …
Run Code Online (Sandbox Code Playgroud)

java android listview android-activity

5
推荐指数
1
解决办法
5483
查看次数

在Android 5的WebView上支持WebGL

我有一个Web项目(取决于WebGL),它适用于计算机,任何浏览器.现在我正在尝试将此项目作为基于Android的手机上的应用程序打开.我使用WebView来实现这一目标.我的手机(Nexus 3)有Android 4.3,而我之前在Android 5之前了解到,WebView组件不支持WebGL.在Android 5中,WebView成为可更新的独立组件,依赖于Chromium版本37(可以更新)并开始支持WebGL.因此,预计我将使用Android 4.3获得错误.

在此之后,我尝试使用另一部手机(三星Galaxy S4搭载Android 5和Chrome版本43).那么应用程序应该运行良好,但仍然在WebView上出错.我试过get.webgl.org仍然是同样的错误:

Error constructing CesiumWidget.

Visit http://get.webgl.org to verify that your web browser and hardware support WebGL. Consider trying a different web browser or updating your video drivers.
Run Code Online (Sandbox Code Playgroud)

详细的错误信息如下:

RuntimeError: The browser supports WebGL, but initialization failed.
Run Code Online (Sandbox Code Playgroud)

错误

at new RuntimeError (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:10657:19)
at new Context (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:96489:19)
at new Scene (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:120928:23)
at new CesiumWidget (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:130986:25)
at AMouseListener.Map2D.initWidget 
Run Code Online (Sandbox Code Playgroud)

这似乎仍然是一个配置问题,所以我试图在Chrome上打开它而不是在WebView上但仍然是同样的错误.我在安装后在Chrome上启用了WebGL.`Firefox工作正常.我有三个问题:

  1. 似乎有什么我做错了,我该如何解决?

  2. Android仍然不支持WebView上的WebGL,是否有任何可能的方法来打开依赖WebGL的应用程序?

  3. 有没有其他方法可以将WebGL项目作为应用程序打开.(我已阅读cordovacocoon.js,但不能肯定是否可以通过这些来完成.)所以,如果有一个工作正常,我宁愿直接去了.

java android google-chrome webgl android-webview

1
推荐指数
1
解决办法
4298
查看次数

如何在正则表达式中捕获多个组?

我正在尝试捕获以下单词,数字:

stxt:usa,city:14
Run Code Online (Sandbox Code Playgroud)

我可以使用以下命令捕获美国和14国:

stxt:(.*?),city:(\d.*)$
Run Code Online (Sandbox Code Playgroud)

但是,当文本是

stxt:usa 
Run Code Online (Sandbox Code Playgroud)

正则表达式不起作用。我尝试使用| 但它没有用。

stxt:(.*?),|city:(\d.*)$
Run Code Online (Sandbox Code Playgroud)

java regex

1
推荐指数
1
解决办法
8204
查看次数

测试数据库类型[H2]的驱动程序在类路径中不可用

我正在尝试运行它Spring security web application,但是当部署web-app时,我得到以下异常:

o.s.b.f.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/baeldung/spring/TestDbConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/baeldung/spring/TestDbConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Driver for test …
Run Code Online (Sandbox Code Playgroud)

java security spring h2

1
推荐指数
1
解决办法
7203
查看次数

在java中获取一组图像的平均图像

我有一套气象RGB类型BufferedImage.我想得到它们的平均图像.通过这种方式,我的意思是获得每个像素的平均值,并从这些值中创建一个新图像.我试过的是这个:

public void getWaveImage(BufferedImage input1, BufferedImage input2){
   // images are of same size that's why i'll use first one's width and height
   int width = input1.getWidth(), height = input1.getHeight();

   BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

   int[] rgb1 = input1.getRGB(0, 0, width, height, new int[width * height], 0, width);
   int[] rgb2 = input2.getRGB(0, 0, width, height, new int[width * height], 0, width);
   for(int i=0; i<width; i++){
      for(int j=0; j<height; j++){
         int rgbIndex = i * width + j; …
Run Code Online (Sandbox Code Playgroud)

java bufferedimage image-processing argb

1
推荐指数
1
解决办法
615
查看次数