I use ByteBuffer.allocateDirect(int) to allocate direct buffer(100M) on non-heap space until java.lang.OutOfMemoryError: Direct buffer memory error thrown.
But when I use jconsole to monitoring the non-heap memory usage, no direct buffer used memory is shown.
import java.nio.ByteBuffer;
import java.util.LinkedList;
public class BufferTest {
public static void main(String[] args) throws InterruptedException {
LinkedList<ByteBuffer> ll = new LinkedList<ByteBuffer>();
int i = 0;
while (true) {
ByteBuffer buffer = ByteBuffer.allocateDirect(100 * 1024 * 1024);
while (buffer.hasRemaining()) {
buffer.put((byte) 1);
}
ll.add(buffer);
System.out.println(i++ + "\t" + buffer.isDirect() + "\t" + buffer.limit());
Thread.sleep(1000);
}
}
}
Related
I've got the following code and somehow the logged time between 1 and 2 is 65-95 ms all the time so I can only record a video grabbed from my webcam with 10-12 fps :-/
(For instance) Looking at How to capture and record video from webcam using JavaCV I shouldn't be that far off from being able to capture a video with 25 or 30 fps from the webcam
grabber = OpenCVFrameGrabber.createDefault(0);
//grabber.setFrameRate(25);
grabber.setImageWidth(1280);
grabber.setImageHeight(720);
grabber.start();
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(() -> {
try {
while (!isStopRequested) {
LOGGER.debug("1: {}", System.currentTimeMillis());
Frame frame = grabber.grab(); // this takes 65-95 ms
LOGGER.debug("2: {}", System.currentTimeMillis());
WritableImage image = frameToImage(frame);
recordingController.processImage(image);
if (isStarted) {
recorder.record(frame);
}
}
} catch (FrameGrabber.Exception fe) {
LOGGER.error("FrameGrabber.Exception when grabbing frame from camera: {}", fe.getMessage());
} catch (FrameRecorder.Exception fre) {
LOGGER.error("FrameRecorder.Exception when recording frame from camera: {}", fre.getMessage());
}
});
The code runs in Java 17 on a laptop with an i7-11800H # 2.30GHz and 64 GB ram, it has 8 cores and not even one of the 8 is fully utilized when running this software, so I don't think it's a hardware issue.
What works for me is this code, in which not only the Thread.sleep() is essential but also the amount of sleep, as 10 or 30 didn't give me good results for the duration, but 40 does (2-2-3-2-2 etc). Don't know why, though and because of this uncertainty I won't accept my own answer as THE answer. I might have to get back to this later
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.image.*;
import ??.screens.RecordingController;
import org.bytedeco.javacv.*;
import org.bytedeco.javacv.Frame;
import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.Mat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.awt.*;
import java.io.File;
import java.nio.ByteBuffer;
import static org.opencv.imgproc.Imgproc.COLOR_BGR2BGRA;
#Component
public class WebcamGrabber {
private static final Logger LOGGER = LoggerFactory.getLogger(WebcamGrabber.class);
private RecordingController recordingController;
Mat javaCVMat = new Mat();
/**
* create buffer only once saves much time!
*/
WritablePixelFormat<ByteBuffer> formatByte = PixelFormat.getByteBgraPreInstance();
OpenCVFrameConverter<Mat> javaCVConv = new OpenCVFrameConverter.ToMat();
/**
* controls if application closes
*/
SimpleBooleanProperty cameraActiveProperty = new SimpleBooleanProperty(false);
OpenCVFrameGrabber frameGrabber;
FFmpegFrameRecorder recorder;
ByteBuffer buffer;
Dimension dimension;
boolean isStarted;
public void init(RecordingController recordingController) {
this.recordingController = recordingController;
}
protected void updateView(Frame frame) {
int w = frame.imageWidth;
int h = frame.imageHeight;
Mat mat = javaCVConv.convert(frame);
opencv_imgproc.cvtColor(mat, javaCVMat, COLOR_BGR2BGRA);
if (buffer == null) {
buffer = javaCVMat.createBuffer();
}
PixelBuffer<ByteBuffer> pb = new PixelBuffer<>(w, h, buffer, formatByte);
final WritableImage wi = new WritableImage(pb);
recordingController.processImage(wi);
}
public void setCameraActive(Boolean isActive) {
cameraActiveProperty.set(isActive);
}
public Boolean getCameraActive() {
return cameraActiveProperty.get();
}
public void shutdown() {
setCameraActive(false);
}
void setVideoView(Frame mat) {
updateView(mat);
}
public void startViewing(Dimension dimension, int cameraIndex) {
this.dimension = dimension;
frameGrabber = new OpenCVFrameGrabber(cameraIndex);
frameGrabber.setFrameRate(25);
frameGrabber.setImageWidth(dimension.width);
frameGrabber.setImageHeight(dimension.height);
try {
frameGrabber.start();
} catch (FrameGrabber.Exception fe) {
LOGGER.error("Exception when trying to start grabbing from camera: {}", fe.getMessage());
}
new Thread(() -> {
setCameraActive(true);
while (getCameraActive()) {
try {
new Thread(() -> {
try {
long startTime = System.currentTimeMillis();
Frame frame = frameGrabber.grab();
System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
setVideoView(frame);
if (isStarted) {
recorder.record(frame);
}
} catch (FrameGrabber.Exception fe) {
LOGGER.error("Exception when grabbing frame from camera: {}", fe.getMessage());
} catch (FrameRecorder.Exception fe) {
LOGGER.error("Exception when recording frame from camera: {}", fe.getMessage());
}
}).start();
Thread.sleep(40);
} catch (InterruptedException ie) {
LOGGER.error("InterruptedException when grabbing frame from camera: {}", ie.getMessage());
}
}
try {
frameGrabber.release();
recorder.stop();
} catch (FrameGrabber.Exception fe) {
LOGGER.error("Exception when releasing frame grabber: {}", fe.getMessage());
} catch (FrameRecorder.Exception fe) {
LOGGER.error("Exception when releasing frame recorder: {}", fe.getMessage());
}
}).start();
}
public void startRecording() {
long start = System.currentTimeMillis();
recorder = new FFmpegFrameRecorder(new File("D:\\data\\" + start + ".mp4"), dimension.width, dimension.height, 2);
recorder.setFormat("mp4");
recorder.setFrameRate(25);
try {
recorder.start();
isStarted = true;
} catch (FrameRecorder.Exception fre) {
LOGGER.error("FrameRecorder.Exception when starting recording: {}", fre.getMessage());
}
Context.getInstance().writeMetadata(start);
}
public void stop() {
if (isStarted) {
isStarted = false;
LOGGER.info("Recording stopped");
}
}
}
Hi I have downloaded pcap4j and winpcap and all jar (jna, pcap4j-core-1.8.2, slf4j-api-1.7.25, slf4j-simple-1.7.25) dependency manually. Added to the project and all compile well.
BUT:
when I began to sniff packet.getHeader() and packet.getPayload() returns null!
if I run manually rpcapd.exe then it works...
why?
package sniffer;
import java.io.IOException;
import org.pcap4j.core.BpfProgram.BpfCompileMode;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PacketListener;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.PcapNativeException;
import org.pcap4j.core.PcapNetworkInterface;
import org.pcap4j.core.PcapNetworkInterface.PromiscuousMode;
import org.pcap4j.packet.Packet;
import org.pcap4j.util.NifSelector;
public class App {
static PcapNetworkInterface getNetworkDevice() {
PcapNetworkInterface device = null;
try {
device = new NifSelector().selectNetworkInterface();
} catch (IOException e) {
e.printStackTrace();
}
return device;
}
public static void main(String[] args) throws PcapNativeException, NotOpenException {
// The code we had before
PcapNetworkInterface device = getNetworkDevice();
System.out.println("You chose: " + device);
// New code below here
if (device == null) {
System.out.println("No device chosen.");
System.exit(1);
}
// Open the device and get a handle
int snapshotLength = 65536; // in bytes
int readTimeout = 50; // in milliseconds
final PcapHandle handle;
handle = device.openLive(snapshotLength, PromiscuousMode.PROMISCUOUS, readTimeout);
String filter = "tcp port 80";
handle.setFilter(filter, BpfCompileMode.OPTIMIZE);
// Create a listener that defines what to do with the received packets
PacketListener listener = new PacketListener() {
#Override
public void gotPacket(Packet packet) {
// Override the default gotPacket() function and process packet
System.out.println(handle.getTimestamp());
System.out.println(packet);
System.out.println(packet.getHeader());///////////////<<<<<<<<<<<------------
}
};
// Tell the handle to loop using the listener we created
try {
int maxPackets = 50;
handle.loop(maxPackets, listener);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Cleanup when complete
handle.close();
}
}
You need to add a packet factory (e.g. pcap4j-packetfactory-static.jar) to your classpath, or Pcap4J creates UnknownPacket instances, getPayload() and getHeader() of which return null, for all packets.
I'm trying to split a PDF document into multiple documents where each document includes the maximum number of pages it can contain where the file size is less than a maximum file size.
My code currently works when running from Eclipse, but when I click on the .jar file, the static method in a java class seems to crash (I can't seem to catch an exception however).
The code that isn't working is:
myListOfDocuments=mysplitter.split(document);
Somehow the JVM bails on the static method when the above line is called. The load seems to work fine, as follows:
PDDocument document=PDDocument.load(aFile);
Any ideas?
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;
public class PDFMaxSizeSplitter {
public static void main(String[] args) {
}
public static ArrayList<File> splitTheFile(File aFile,long maxSize){
ArrayList<File> resultFiles = new ArrayList<File>();
//Checks to see if file is already small enough
if (aFile.length() <= maxSize){
resultFiles.add(aFile);
return resultFiles;
}
//checks to see if it's a directory
if (aFile.isDirectory()){
resultFiles.add(aFile);
return resultFiles;
}
try {
PDDocument document = PDDocument.load(aFile);
Splitter mysplitter = new Splitter();
List<PDDocument> myListOfDocuments = mysplitter.split(document);
int docNumber = 0;
while (myListOfDocuments.size()>0){
long theResults = 0;
theResults = getChunk(myListOfDocuments,0,(long) (myListOfDocuments.size()-1),maxSize);
PDDocument newPDFDoc = new PDDocument();
for (long pageindex=0; pageindex<=theResults; pageindex++){
newPDFDoc.addPage(myListOfDocuments.get((int) pageindex).getPage(0));
}
File newFile = new File(aFile.getParentFile() +
File.separator +
aFile.getName().replace(".pdf", "") +
"Part" +
String.format("%03d", docNumber) +
".pdf");
//System.out.println(newFile.getCanonicalFile());
newPDFDoc.save(newFile);
resultFiles.add(newFile);
myListOfDocuments=myListOfDocuments.subList((int) (theResults)+1, (myListOfDocuments.size()));
newPDFDoc.close();
docNumber++;
}
document.close();
} catch (IOException e) {
e.printStackTrace();
}
return resultFiles;
}
private static long getChunk(List<PDDocument> thePages, long lowPage, long highPage, long maxSize) throws IOException{
//System.out.println("low " + lowPage + " high page: " + highPage);
if ( (highPage-lowPage)<=1 ){
if(PDFMaxSizeSplitter.testSize(thePages,0,highPage)<=maxSize){
return highPage;
} else{
return lowPage;
}
} else if (PDFMaxSizeSplitter.testSize(thePages, 0,lowPage+ (highPage-lowPage)/2)<=maxSize){
return PDFMaxSizeSplitter.getChunk(thePages, lowPage + (highPage-lowPage)/2, highPage,maxSize);
}
else {
return PDFMaxSizeSplitter.getChunk(thePages, lowPage, lowPage + (highPage-lowPage)/2,maxSize);
}
}
private static long testSize(List<PDDocument> thePages, long start, long stop) throws IOException{
//System.out.println("Trying: " + (new Long(start)).toString() + " to " + (new Long(stop)).toString());
PDDocument testerdocument = new PDDocument();
//Path tempPath = Files.createTempFile((new Long(start)).toString(), (new Long(stop)).toString());
//System.out.println("Creating tempPath " +tempPath.toString());
//File tempFile=new File(tempPath.toString());
ByteArrayOutputStream tempFile = new ByteArrayOutputStream();
for (long pageindex=start; pageindex<=stop; pageindex++){
testerdocument.addPage(thePages.get((int) pageindex).getPage(0));
}
testerdocument.save(tempFile);
long thefilesize = tempFile.size();
//long thefilesize = (tempFile.length());
//Files.deleteIfExists(tempPath);
tempFile.reset();
testerdocument.close();
return thefilesize;
}
}
-----------edit--------------
It turns out the JVM was running out of memory.
It turns out the JVM was running out of memory. I added a jvm argument to increase the memory. Also, I switched to the 64 bit jvm mode by using the argument -d64 on the jvm. Also, I have been using the disk drive cached memory management found in pdfbox, e.g., new PDDocument(aFile, MemoryUsageSetting.setupTempFileOnly());
With these settings, I can handle several gigabytes of files. Now in the code, I try to load the documents into direct memory and catch the out of memory exception to switch to a low memory mode. In the low memory mode I use the MemoryUsageSetting.setupTempFileOnly() to avoid using too much of the heap.
I wrote a ServerResource below with restlet-android-2.1.4. If the I set SIZE to 1024 * 12 + 485, it works. But if I change SIZE to 1024 * 12 + 486 this handle will pending.
public class DataResource extends ServerResource {
public static final int SIZE = 1024 * 12 + 485;
#Get
public Representation getResource(Representation entity) {
return new OutputRepresentation(MediaType.ALL) {
#Override
public void write(OutputStream outputStream) throws IOException {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < SIZE; i++) {
sb.append('E');
}
outputStream.write(sb.toString().getBytes());
outputStream.close();
}
};
}
}
Dive into the code, change the write function in WritableSocketChannel.java(in restlet source code) and it will work.
I don't know whether it's a bug.
from
public int write(ByteBuffer src) throws IOException {
return getWrappedChannel().write(src);
}
to
public int write(ByteBuffer src) throws IOException {
int count = 0;
while (src.hasRemaining()) {
count += getWrappedChannel().write(src);
}
return count;
}
According to java doc.
Some types of channels, depending upon their state, may write only
some of the bytes or possibly none at all. A socket channel in
non-blocking mode, for example, cannot write any more bytes than are
free in the socket's output buffer.
I am trying to create a leader election protocol using JGroups so that N instances of my program can elect a master and all clients get the ip of this master.
More or less the current implementation relies on each instance trying to acquire a lock on lock-channel and when it successfully acquires this channel it becomes master and all others switch to clients.
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.*;
import org.jgroups.*;
import org.jgroups.blocks.locking.LockService;
public class AutoDiscovery
{
static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AutoDiscovery.class); //used for logging purposes (see log4j library)
/* this variable indicates whether I have become the master or I'm just a client*/
public volatile AtomicBoolean becomeMaster = new AtomicBoolean(false);
/* The address of the server if we are a client or of ourself if we are
* server */
public String serverAddress;
/* A channel on which to acquire a lock, so that only one can become server */
private JChannel lockChannel;
/* A shared channel ffor communication between client and master*/
private JChannel communicationChannel;
private LockService lockService;
/* A thread which tries to acquire a lock */
private Thread acquiringThread;
/* A thread which listens for the server ip which may change */
private Thread listeningThread;
/* A thread which lists the status and initializes the acquiring thread*/
private Thread statusThread;
private String name;
/* If we pass from being a client to being a server we must stop the listening
* thread however we cannot call listeningThread.stop() but instead we change
* the stopListening boolean to true */
private boolean stopListening = false;
/* This lock communicates I have finally become either master or client so
* the serverAddress and becomeMaster variables are correctly set */
public final Object finishedLock = new Object();
public static void main(String[] args) throws Exception
{
Thread.currentThread().setName("MyMainThread");
Random rand = new Random();
AutoDiscovery master = new AutoDiscovery("Node" + rand.nextInt(10));
master.lockChannel = new JChannel(AutoDiscovery.class.getResource("/resource/udp.xml"));
master.lockChannel.connect("lock-channel");
master.communicationChannel = new JChannel(AutoDiscovery.class.getResource("/resource/udp.xml"));
master.communicationChannel.connect("communication-channel");
master.lockService = new LockService(master.lockChannel);
master.startStatusPrinterThread();
}
public AutoDiscovery(String name)
{
this.name = name;
}
public AutoDiscovery()
{
try
{
Thread.currentThread().setName("MyMainThread");
Random rand = new Random();
this.name = ("Node" + rand.nextInt(10));
lockChannel = new JChannel(AutoDiscovery.class.getResource("/resource/udp.xml"));
lockChannel.connect("lock-channel");
communicationChannel = new JChannel(AutoDiscovery.class.getResource("/resource/udp.xml"));
communicationChannel.connect("communication-channel");
lockService = new LockService(lockChannel);
startStatusPrinterThread();
}
catch (Exception ex)
{
Logger.getLogger(AutoDiscovery.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void startAcquiringThread()
{
acquiringThread = new Thread()
{
#Override
public void run()
{
while (true)
{
//if you have become Master send your ip every now and then
if (becomeMaster.get())
{
try
{
communicationChannel.send(new Message(null, null, "serverip " + serverAddress));
}
catch (Exception ex)
{
Logger.getLogger(AutoDiscovery.class.getName()).log(Level.SEVERE, null, ex);
}
}
else
{
try
{
Thread.currentThread().setName(name + "AcquiringThread");
Lock lock = lockService.getLock("serverLock");
if (lock.tryLock(4, TimeUnit.SECONDS))
{
becomeMaster.set(true);
stopListening = true;
/* Now that I'm server I must find out my own ip address on which to listen */
Enumeration<NetworkInterface> networkInterfaces;
try
{
networkInterfaces = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(networkInterfaces))
{
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses))
{
if (isIPAddress(inetAddress.getHostAddress())
&& !inetAddress.getHostAddress().equals("127.0.0.1"))
{
serverAddress = inetAddress.getHostAddress();
}
}
}
/* I notify to the rest of the program I have correctly initialized
* becomeMaster and serverAddress */
synchronized (finishedLock)
{
finishedLock.notify();
}
}
catch (Exception e)
{
Logger.getLogger(AutoDiscovery.class.getName()).log(Level.SEVERE, null, e);
System.exit(0);
}
log.info(Thread.currentThread().getName() + ": I acquired lock! will become master! my ip is " + serverAddress);
}
else
{
becomeMaster.set(false);
stopListening = false;
if (listeningThread == null || !listeningThread.isAlive())
{
if (!stopListening) //??? this codnition might be useless
{
startListeningThread();
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
sleep(5000L);
}
catch (InterruptedException ex)
{
Logger.getLogger(AutoDiscovery.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
acquiringThread.setDaemon(true);
acquiringThread.start();
}
public void startListeningThread()
{
listeningThread = new Thread()
{
#Override
public void run()
{
try
{
while (true)
{
Thread.currentThread().setName(name + "ListeningThread");
communicationChannel.setReceiver(new ReceiverAdapter()
{
#Override
public void receive(Message msg)
{
if (msg.getObject() != null)
{
String leaderServerAddress = (msg.getObject().toString().substring(9));
if (isIPAddress(leaderServerAddress))
{
serverAddress = leaderServerAddress;
log.info(name + " Master server has ip" + serverAddress);
/* I notify to the rest of the program I have correctly initialized
* becomeMaster and serverAddress */
synchronized (finishedLock)
{
finishedLock.notify();
}
}
else
{
log.info(name + ": discarded message " + msg.getObject().toString());
}
}
}
});
sleep(10000L);
if (stopListening)
{
return;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
listeningThread.setDaemon(true);
listeningThread.start();
}
private void startStatusPrinterThread()
{
statusThread = new Thread()
{
#Override
public void run()
{
Thread.currentThread().setName(name + "StatusPrinterThread");
startAcquiringThread();
while (true)
{
try
{
if (becomeMaster.get())
{
log.info(name + " startStatusPrinterThread(): I am happily a Master!");
}
else
{
if (!acquiringThread.isAlive())
{
startAcquiringThread();
}
}
sleep(5000L);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
};
statusThread.setDaemon(true);
statusThread.start();
}
private static boolean isIPAddress(String str)
{
Pattern ipPattern = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
return ipPattern.matcher(str).matches();
}
}
now my current udp.xml is
<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.0.xsd">
<UDP
mcast_port="${jgroups.udp.mcast_port:45588}"
tos="8"
ucast_recv_buf_size="20M"
ucast_send_buf_size="640K"
mcast_recv_buf_size="25M"
mcast_send_buf_size="640K"
loopback="true"
level="WARN"
log_discard_msgs="false"
max_bundle_size="64K"
max_bundle_timeout="30"
ip_ttl="${jgroups.udp.ip_ttl:8}"
enable_diagnostics="true"
thread_naming_pattern="cl"
timer_type="new"
timer.min_threads="4"
timer.max_threads="10"
timer.keep_alive_time="3000"
timer.queue_max_size="500"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="true"
thread_pool.queue_max_size="10000"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="Run"/>
<PING timeout="2000"
num_initial_members="3"/>
<MERGE2 max_interval="30000"
min_interval="10000"/>
<FD_SOCK/>
<FD_ALL/>
<VERIFY_SUSPECT timeout="1500" />
<BARRIER />
<pbcast.NAKACK exponential_backoff="300"
xmit_stagger_timeout="200"
use_mcast_xmit="false"
discard_delivered_msgs="true"/>
<UNICAST />
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000"
view_bundling="true"/>
<UFC max_credits="2M"
min_threshold="0.4"/>
<MFC max_credits="2M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K" />
<pbcast.STATE_TRANSFER />
<CENTRAL_LOCK />
<!-- pbcast.FLUSH /-->
</config>
Now the above works when I run N instances of the program on the same machine (with N-1 members becoming client and 1 becoming master).
When run on two different machines both connected to the same LAN, apparently after calling JChannel.connect() with the same clustername in each member, each member creates its channel and no common cluster is created. The result is that when sending messages to the clients the other master sees a different physical address for the same cluster name and all messages are dropped.
So I get warnings like:
7683 [Incoming-1,communication-channel,pc-home-41714] WARN org.jgroups.protocols.pbcast.NAKACK - [JGRP00011] pc-home-41714: dropped message 293 from non-member cf8b4ea6-8cc8-cb21-538f-b03f3fa7413d (view=[pc-home-41714|0] [pc-home-41714])
1207996 [TransferQueueBundler,communication-channel,pc-home-5280] WARN org.jgroups.protocols.UDP - pc-home-5280: no physical address for cf8b4ea6-8cc8-cb21-538f-b03f3fa7413d, dropping message
1209526 [TransferQueueBundler,lock-channel,pc-home-59082] WARN org.jgroups.protocols.UDP - pc-home-59082: no physical address for efbe6408-0e21-d119-e2b8-f1d5762d9b45, dropping message
If I change udp.xml loopback="true" to loopback="false" what happens is that they both connect to the same cluster but then they give an error like:
55539 [Node0StatusPrinterThread] INFO plarz.net.planningig.autodiscovery.AutoDiscovery - Node0 startStatusPrinterThread(): I am happily a Master!
59077 [TransferQueueBundler,lock-channel,pc-test-6919] ERROR org.jgroups.protocols.UDP - pc-test-6919: exception sending bundled msgs: java.lang.Exception: dest=/fe80:0:0:0:226:18ff:fece:6ccc%2:43109 (130 bytes):, cause: java.io.IOException: Network is unreachable
59505 [TransferQueueBundler,communication-channel,pc-test-35303] ERROR org.jgroups.protocols.UDP - pc-test-35303: exception sending bundled msgs: java.lang.Exception: dest=/fe80:0:0:0:226:18ff:fece:6ccc%2:55053 (139 bytes):, cause: java.io.IOException: Network is unreachable
Error:
[Server:ha-server-3] 13:59:13,122 WARNING [org.jgroups.protocols.UDP]
(OOB-15,null) null: no physical address for
766de5c9-8ac2-6d30-89ef-78d39aa5f7eb, dropping message
In My case, it was due to having multiple jboss clusters at a same
network and each of the clusters were having same name. For example
ha-server-1 and ha-server-2 existed at two different clusters in
different machines.
Cluster-1(10.10.10.10): |
+- ha-server-1
+- ha-server-2
Cluster-2(10.10.10.20): |
+- ha-server-1
+- ha-server-2
I have resolved this problem by changing the ha-server names. Note:
Both were independent cluster. I assume it happened due to the
multicast issue of JGroups. Any further explanation from an expert
like you will be nice.
refer to http://icfun.blogspot.com/2013/10/no-physical-address-for-766de5c9-8ac2.html