LiveConnect and (Re: func.apply() throws Error -2147467259)

R

Richard Maher

Hi Stevo,

Stevo said:
You'll probably have to give (the experts here) more info on what stuf is.

Personally, the only time I'm ever using myFunc.apply, I'm passing in
(this,arguments) to relay all of my received arguments onto another
function.

Fair enough, but as they say in the movies "it's complicated"! Please see
below for randomator.html (<500 lines). This is a next to useless random
employee picker that is designed just to work my Applet's socket while a
more useful employee lookup page/tab is handling user requests.

Please stay with me as it's definitely worthwhile in the end: -

Randomator uses an Applet to connect back to the codebase via a TCP/IP
socket.
This Socket, along with much other stuff, is held in static variable that is
common among all like-minded applets accross any number of tabs in a browser
instance.
To further complicate things, all applet instances write to the socket when
instructed by Javascript. but there is a single common "reader" thread that
does the multiplexing of responses to the correct tab and invokes the
appropriate JSObject.call() callback. (Tier3Client is the gateway to the
applet functionality and will be included under separate post)

Still with me? Good. . .

The onload event creates the default of 1 EmpPicker()
From here on in the user can increase/decrease the number of EmpPickers from
0 to 5 and vary the DIV-fade interval from 1 to 5 secs. (IE8 with 2 emps,
1sec fade, and one tab fails at mem usage 64MB when not the above error.
Firefox handles 5 Emps at one sec but *eventually* fails with multiple tabs
doing the same thing)

When not dying each EmpPicker's work schedule involves: -
1) Asking the server for a random employee (eventsMgr.setAST(carousel,0))
2) The "carousel" function SENDs a request to the server and specifies
"positionDiv" as the callback function
3) Because the Async flag on the SEND was set to false the Applet instance
will now wait in JAVA for the reader thread (well, actually, the Javascript
this.rendezvous() function) to tell it to proceed.
*4) Upon receiving the server response the Reader thread calls
myJSObject.call("dispatcher", args)
5) The "dispatcher" tries to call your callback "positionDiv" which works
many times before failing
6) after the coloured DIV has been populated with the employee details the
DIV begins fading (eventsMGR.setAST(fadeIt, FADEINTERVAL)
7) "fadeIt" keeps scheduling itself until the fade is/should-be complete and
then asks for another employee

* Delaying the server response by a 1 sec wait during testing certainly
threw up some odd behaviour :-(

If I've introduced some memory-leak/circular-reference or other basic
Javascript variable scoping error and am stomping on EmpPicker()
instances/memory then please let me know.

Should I make positionDiv() static and pass it the EmpPicker instance or
Index as an argument? (Is "this" causing problems?)

Threading or timer issue?

All relevant advice welcome.

Cheers Richard Maher

PS. I'm really not in the mood for the regular self-appointed newsgroup
sheriffs or incurable wankers discussing the relevance of the post,
spelling, cross-posting, overall strategy or design philosophy. Please find
someone else to annoy for today!

PPS. For the curiously sceptical please see: -
http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/index.html
*Now in ORACLE livery!*

Randomator.html: -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta name = "author"
content = "Richard Maher"/>
<meta name = "description"
content = "Tier3Client random Employee picker"/>

<style>

html
{
height: 100%
}

body
{
background-color: Gray;
margin: 0px;
padding: 0px;
}

input.knob
{
font-family: arial;
font-weight: bold;
background-color: DarkGray;
color: black;
font-size: 18px;
height: 26px;
width: 20px;
padding: 0px;
margin: 1px;
}

.cntr
{
font-family: georgia;
font-weight: bold;
font-size: 18px;
background-color: white;
color: black;
height: 20px;
width: 20px;
text-align: center;
}

table#empDetails caption
{
font-family: Arial;
font-weight: bold;
font-size: 12px;
color: gray;
}

table#empDetails
{
width: 100%;
}

.promptItem
{
text-align: right;
}

.dataItem
{
font-weight: bold;
}

div#ctrlPanel
{
background-color: Turquoise;
color: black;
font-family: Georgia;
font-size: 12px;
margin: 0px;
padding: 0px;
border-style: solid;
border-width: 1px;
border-color: black;
height: 30px;
}

.screenHdr
{
text-align: center;
font-size: 22px;
font-weight: bold;
color: Black;
}

</style>

<script type="text/javascript" src="Tier3Client.js" ></script>

<script type="text/javascript">

var t3Client;
var fadeSecs;
var empsCnt;

EmpPicker.FADEMIN = 1000;
EmpPicker.FADEMAX = 5000;
EmpPicker.MAXEMPS = 5;

EmpPicker.fadeDuration = 3000;
EmpPicker.activeDivs = [];

function EmpPicker()
{
var DIVCOLORS = new Array("lightgrey",
"yellow",
"magenta",
"lawngreen",
"cyan");
var FADEINTERVAL = 50;
var HDRHEIGHT = 30;
var DIVWIDTH = 300;
var DIVHEIGHT = 150;
var BORDERWIDTH = 4;

var targetDiv = document.createElement("div");
var startTime;
var endTime;
var fadeDuration;

var shuttingDown = false;

targetDiv.style.visibility = "hidden";
targetDiv.style.position = "absolute";
targetDiv.style.width = DIVWIDTH+"px";
targetDiv.style.height = DIVHEIGHT+"px";

var colorIndex = EmpPicker.activeDivs.length %
DIVCOLORS.length;
targetDiv.style.backgroundColor
= DIVCOLORS[colorIndex];

targetDiv.style.color = "black";
targetDiv.style.fontSize = "12px";
targetDiv.style.borderTop = "1px solid black";
targetDiv.style.borderRight= "3px solid black";
targetDiv.style.borderBottom
= "3px solid black";
targetDiv.style.borderLeft = "1px solid black";
targetDiv.style.padding = "0px";
targetDiv.style.margin = "0px";

document.body.appendChild(targetDiv);

var eventsMgr = function()
{
var AST = 0;

var setAST =
function(entryPoint,timer){
AST = setTimeout(entryPoint,timer);
empsCnt.value = AST;
};

var cancelAST =
function(){
fadeSecs.value = AST;
clearTimeout(AST);
};

return {
setAST : setAST,
cancelAST : cancelAST
};
}();

var positionDiv =
function positionDiv(respMsg)
{
this.rendezvous();
if (shuttingDown){
// this.rendezvous();
// alert("PD exit");
return;
}

targetDiv.style.visibility = "hidden";
targetDiv.style.opacity = "";
targetDiv.style.filter = "";
targetDiv.style.zIndex = "1000";

var recType = respMsg.substr(0,2);

switch (recType)
{
case "00" :
// alert(respMsg.substr(2));
break;
case "31" :
targetDiv.innerHTML =
'<table border="0" cellpadding="1px" '
+
' align="center" id="empDetails"> '
+
' <caption>Totally Random Employee</caption>'
+
' <tr><td class="promptItem">Employee Id: </td>'
+
' <td class="dataItem">'+ respMsg.substr(2,5)
+'</td></tr>' +
' <tr><td class="promptItem"> Name:</td>'
+
' <td class="dataItem">'+ respMsg.substr(7,28)
+'</td></tr>' +
' <tr><td class="promptItem">Sex: </td>'
+
' <td class="dataItem">'+ respMsg.substr(35,1)
+'</td></tr>' +
' <tr><td span class="promptItem">Department: </td>'
+
' <td class="dataItem">'+ respMsg.substr(36,30)
+'</td></tr>' +
' <tr><td class="promptItem">Current Salary: </td>'
+
' <td class="dataItem">'+ respMsg.substr(66,12)
+'</td></tr>' +
' <tr><td class="promptItem">Dept Average: </td>'
+
' <td class="dataItem">'+ respMsg.substr(78,12)
+'</td></tr>' +
'</table><br>';
break;
default :
throw new Error("Received Invalid Record Type [" + recType +
"]");
}

var canvas = function(){

var height = 0;
var width = 0;
var scrollTop = 0;
var scrollLeft = 0;

if (window.innerHeight){
width = window.innerWidth;
height = window.innerHeight;
}
else if (document.documentElement &&
document.documentElement.clientHeight){
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else if (document.body){
width = document.body.clientWidth;
height = document.body.clientHeight;
}

if (typeof( window.pageYOffset ) == 'number'){
scrollTop = window.pageYOffset;
scrollLeft = window.pageXOffset;
}
else if (document.documentElement &&
document.documentElement.scrollTop){
scrollTop = document.documentElement.scrollTop;
scrollLeft = document.documentElement.scrollLeft;
}
else if (document.body){
scrollTop = document.body.scrollTop;
scrollLeft = document.body.scrollLeft;
}

return {height : height, width : width, scrollTop : scrollTop,
scrollLeft : scrollLeft};

}();

var divTop = Math.floor(Math.random()*(canvas.height -
(DIVHEIGHT + BORDERWIDTH + HDRHEIGHT)));
divTop = divTop < 0 ? 0 : divTop;
var divLeft = Math.floor(Math.random()*(canvas.width -
(DIVWIDTH + BORDERWIDTH)));
divLeft = divLeft < 0 ? 0 : divLeft;

targetDiv.style.left = divLeft + "px";
targetDiv.style.top = (divTop + HDRHEIGHT) + "px";
targetDiv.style.visibility = "visible";

startTime = new Date().getTime();
endTime = startTime + EmpPicker.fadeDuration;
fadeDuration = EmpPicker.fadeDuration
eventsMgr.setAST(fadeIt,FADEINTERVAL);

}

var fadeIt =
function(){
var now = new Date().getTime();
if (now >= endTime) {
targetDiv.style.visibility = "hidden";
eventsMgr.setAST(carousel,300);
}else{
var fadeFactor = 1 - (now - startTime) / fadeDuration;
targetDiv.style.opacity = fadeFactor;
targetDiv.style.filter = "alpha(opacity="+(fadeFactor*100)+")";
targetDiv.style.zIndex--;
eventsMgr.setAST(fadeIt,FADEINTERVAL);
}
}

var carousel =
function(){
if (shuttingDown){
// alert("no go");
return;
}
t3Client.send("30",positionDiv,false);
}

this.shutdown =
function(){
shuttingDown = true;
eventsMgr.cancelAST();
targetDiv.style.visibility = "hidden";
document.body.removeChild(targetDiv);
targetDiv = null;
}

EmpPicker.activeDivs.push(this);
eventsMgr.setAST(carousel,0);

return this;
}

function load()
{
fadeSecs = document.getElementById("fadeSecs");
empsCnt = document.getElementById("empsCnt");

try {
t3Client = new Tier3Client(
"Demo", "http://192.168.1.159/Applets/",
2048, 1022, "ISO-8859-1", "N", Tier3Client.GUIAWT,
null,Tier3Client.WARNING);
} catch (err){
alert((err.description||err.message));
throw err;
}

if (t3Client == null || t3Client == undefined) {
alert("Error connecting to Tier3 Client")
throw new Error("Could not activate Tier3 Client");
}

fadeSecs.value = EmpPicker.fadeDuration / 1000;

t3Client.appendConsoleMsg("Employee Randomator successfully loaded");

addEmp();

return;
}

function setDuration(stepValue)
{
var newDuration = EmpPicker.fadeDuration + stepValue;
if (newDuration < EmpPicker.FADEMIN || newDuration >
EmpPicker.FADEMAX)
return;

EmpPicker.fadeDuration = newDuration;
fadeSecs.value = EmpPicker.fadeDuration / 1000;

}

function addEmp()
{
if (EmpPicker.activeDivs.length == EmpPicker.MAXEMPS)
return;

var newEmp = new EmpPicker();
empsCnt.value = EmpPicker.activeDivs.length;
}

function delEmp()
{
if (EmpPicker.activeDivs.length == 0)
return;

var victim = EmpPicker.activeDivs.pop();
victim.shutdown();

empsCnt.value = EmpPicker.activeDivs.length;

}

</script>

</head>
<body onload="load();" onunload="(function(){});">
<div id="ctrlPanel">
<table
style="table-layout: fixed;"
width="100%"
border="0"
frame="void"
cellpadding="0"
cellspacing="0"
rules="none"
<tr
valign="middle"
<td
width="40%"
style="text-align: right;"
valign="middle"
Fade Duration :
<input
type="button"
class="knob"
onclick="setDuration(1000)"
name="fadeUp"
value="^"
title="Increase Fade Time"
/>
<input
type="text"
class="cntr"
id="fadeSecs"
readonly="readonly"
value="0"
size=1
title="Duration of fade in seconds"
/>
<input
type="button"
class="knob"
style="font-size: 14px;"
onclick="setDuration(-1000)"
name="fadeDown"
value="v"
title="Decrease Fade Time"
/>
</td>
<td
width="20%"
class="screenHdr"
valign="middle"
>Randomator</td>

<td
width="40%"
style="text-align: left;"
valign="middle"
<input
type="button"
class="knob"
onclick="addEmp()"
name="empsUp"
value="^"
title="Pick more employees"
/>
<input
type="text"
class="cntr"
id="empsCnt"
readonly="readonly"
value="0"
size=1
title="Number of employees to pick"
/>
<input
type="button"
class="knob"
style="font-size: 14px;"
onclick="delEmp()"
name="empsDown"
value="v"
title="Pick fewer employees"
/>
: Concurrent Selections
</td>
</tr>
</table>
</div>
</body>
</html>
 
R

Richard Maher

See below for the Tier3Client class.

The code gets to the "dispatcher" but barfs at
callback.apply(this,callbackArgs);

Once again all useful assistance greatly appreciated. (No, I said not you,
or you!)

Cheers Richard Maher

PS. Some side issues which I'll probably bring up again late but in case
anyone knows the answer nowr: -

Opera won't wait for the "this.chan = document.getElementById(appletId);"
when the Applet was appended with appendChild(div); Chrome works the first
time but subsequent tabs are subject to a timing condition. Safari has it's
own bollocks "no protocol on URL exception" and fails SENDing (i think)
because the codebase is not the same as the document base?


/**
* Copyright (c) Richard Maher. All rights reserved.
*
* Tier3Client class bridges Javascript and Applet
* functionality.
*/

function Tier3Client(application,
codeBase,
port,
maxBuf,
hostCharSet,
sslReqd,
guiToolkit,
idleTimeout,
verbosity)
{
if (arguments.length < 4) {
throw new Error("Insufficient arguments for Tier3Client");
}

if (!navigator.javaEnabled()) {
alert("You must enable Java Applets in your browser\n" +
"before you can successfully access this page");
throw new Error("Java Applets are not enabled for browser");
}

this.application = application;
this.codeBase = codeBase;
this.port = port;
this.maxBuf = maxBuf;

this.hostCharSet = (hostCharSet == undefined) ? "ISO-8859-1" :
hostCharSet;
this.sslReqd = (sslReqd == undefined) ? "N" :
sslReqd;
this.guiToolkit = (guiToolkit == undefined) ? Tier3Client.GUIAWT :
guiToolkit;
this.idleTimeout = (idleTimeout == undefined) ? 0 :
idleTimeout;
this.verbosity = (verbosity == undefined) ? Tier3Client.WARNING :
verbosity;

var appletId = "Tier3__" + this.application + "_Applet";

try {
var idTaken = document.getElementById(appletId);
}
catch (err) {};

if (idTaken != null) {
throw new Error("Tier3 Client already registered for " +
this.application);
return;
}

var archiveName = "tier3Client.jar";
var className = "tier3Client/Tier3Application";

var appletParams = [{"name":"archive",
"value":archiveName },
{"name":"codebase",
"value":codeBase },
{"name":"code",
"value":className },
{"name":"java_version",
":"1.6+" },
{"name":"mayscript",
lue":"true" },
{"name":"scriptable",
ue":"true" },
{"name":"codebase_lookup",
"false" },
{"name":"APPLICATION",
"value":application },
{"name":"PORT",
"value":port },
{"name":"MAXBUF",
"value":maxBuf },
{"name":"HOSTCHARSET",
"value":this.hostCharSet},
{"name":"SSLREQD",
"value":this.sslReqd },
{"name":"GUITOOLKIT",
"value":this.guiToolkit },
{"name":"IDLETIMEOUT",
"value":this.idleTimeout},
{"name":"VERBOSITY",
"value":this.verbosity }];
var startParam = 0;

var objectTag = "<object classid=";

if (/Internet Explorer/.test(navigator.appName)) {
objectTag = objectTag +
'"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
} else {
objectTag = objectTag +
'"java:' + className + '.class" type="application/x-java-applet"
' +
'archive="' + codeBase + archiveName + '" ';
startParam = 1;
}

objectTag = objectTag + ' width= "0" height= "0" id="' + appletId +
'">';

for (i=startParam; i<appletParams.length; i++){
objectTag = objectTag + '<param name ="' + appletParams.name +
'" ' +
'value ="' + appletParams.value +
'">';
}

objectTag = objectTag + "</object>";

var appletDiv = document.createElement("div");
appletDiv.innerHTML = objectTag;

try {
document.body.appendChild(appletDiv);
this.chan = document.getElementById(appletId);
}
catch(err) {
alert("Tier3 unable to load applet for " + this.application +
": -\n" +
(err.description||err.message));
this.chan = null;
};
if (this.chan == null) {
throw new Error("Tier3 was unable to initialize the applet for " +
this.application);
} else {
try {
if (!this.chan.isAuthorized()) {
throw new Error("Tier3 User Authentication unsuccessful");
}
}
catch(err) {
this.chan.setAttribute("id",null);
this.chan = null;
throw new Error("Tier3 unable to load applet for " +
this.application + ": -\n" +
(err.description||err.message));
}
}

Tier3Client.applications[this.application] = this;
return this;
}

Tier3Client.FACPREFIX = "T3$";
Tier3Client.MAJVERS = 1;
Tier3Client.MINVERS = 0;
Tier3Client.GUIAWT = 1;
Tier3Client.DEBUG = 0;
Tier3Client.INFO = 1;
Tier3Client.WARNING = 2;
Tier3Client.ERROR = 3;
Tier3Client.FATAL = 4;

Tier3Client.errorPage = "Tier3Error.html";
Tier3Client.logoffPage = "Tier3Logoff.html";

Tier3Client.launder =
function(jsobject) {
return jsobject;
};

Tier3Client.prototype = {

send:
function(msgBody, callback, async)
{
if (arguments.length < 2) {
throw new Error("Insufficient arguments for send(msgBody,
callback)");
}

if (typeof callback != "function") {
throw new Error("The 'callback' parameter must be a
function");
}

var noWait = true;
if (arguments.length > 2) {
if (typeof async != "boolean") {
throw new Error("The 'async' parameter must be a
boolean");
}
noWait = async;
}

var chan = this.chan;
var callbackArgs = new Array();
var responseCnt = 0;
var i = 0;

var msgCandidate =
{
msgSlotId : -1,
msgSeqNum : -1,
chan : chan,
callback : callback,
callbackArgs : callbackArgs,

dispatcher :
function(responseMsg,
msgSlotId,
msgSeqNum)
{
this.responseCnt++;
this.msgSlotId = msgSlotId;
this.msgSeqNum = msgSeqNum;
callbackArgs[0] = responseMsg;

try {
callback.apply(this, callbackArgs);
}
catch (err) {
var errMsg = "Error calling callback
routine: -\n";
for (var prop in err) {
errMsg += " Property: " + prop + " Value: " +
err[prop] + "\n";
}
errMsg += " toString() = " + err.toString() +
"\n";
throw new Error(errMsg);
}
},

getMsgSeqNum :
function() {
return this.msgSeqNum;
},

getResponseCnt:
function() {
return this.responseCnt;
},

rendezvous :
function() {
return chan.rendezvous();
}

};

for (i=3; i<arguments.length; i++) {
callbackArgs[i - 2] = arguments;
}

return chan.send(msgCandidate, msgBody, noWait);
},

appendConsoleMsg:
function(msg)
{
this.chan.appendConsoleMsg(msg);
}
};

Tier3Client.applications = {};
 
J

Jorge

(...)
PS. I'm really not in the mood for the regular self-appointed newsgroup
sheriffs or incurable wankers discussing the relevance of the post,
spelling, cross-posting, overall strategy or design philosophy. Please find
someone else to annoy for today!
(...)

Me ROTFLOL-ly
 
J

Jorge

      var eventsMgr = function()
      {
        var AST = 0;

        var setAST =
          function(entryPoint,timer){
            AST = setTimeout(entryPoint,timer);
            empsCnt.value = AST;
^^^^^^^^^^^^^^^^^^^^

Sure ?
          };

        var cancelAST =
          function(){
            fadeSecs.value = AST;
^^^^^^^^^^^^^^^^^^^^^

Why ?
 
L

Lew

Richard said:
Fair enough, but as they say in the movies "it's complicated"! Please see
below for randomator.html (<500 lines). This is a next to useless random
employee picker that is designed just to work my Applet's socket while a
more useful employee lookup page/tab is handling user requests. ....
Randomator uses an Applet to connect back to the codebase via a TCP/IP
socket.

Could you show the applet code? Those of us reading from clj.programmer are
probably in a much better position to discuss Java issues than Javascript issues.
This Socket, along with much other stuff, is held in static variable that is
common among all like-minded applets accross any number of tabs in a browser
instance.

There an awful lot of risks to static variables, mainly with respect to
concurrency collisions.

....
3) Because the Async flag on the SEND was set to false the Applet instance
will now wait in JAVA [sic] for the reader thread (well, actually, the Javascript
this.rendezvous() function) to tell it to proceed.

Seeing the Java code will really help us here in clj.programmer.
*4) Upon receiving the server response the Reader thread calls
myJSObject.call("dispatcher", args)
5) The "dispatcher" tries to call your callback "positionDiv" which works
many times before failing

All this back-and-forth between Java and Javascript seems complicated. Well,
you did say that, but I imagine there must be a more straightforward way to
deal with it.
...
Should I make positionDiv() static and pass it the EmpPicker instance or
Index as an argument? (Is "this" causing problems?)

Redux on warning about static variables.
PS. I'm really not in the mood for the regular self-appointed newsgroup
sheriffs or incurable wankers

Pot, meet kettle. Kettle, meet pot.
spelling, cross-posting, overall strategy or design philosophy. Please find
someone else to annoy for today!

Right back atcha.
 
J

Jorge

On Jan 30, 11:01 am, "Richard Maher" <[email protected]>
wrote:
(...)

Removing the applet and the back-and-forth between Java-JS the
resulting java-less version seems to run fine:

http://jorgechamorro.com/cljs/095/

<script type="text/javascript">
function Tier3Client () {
(this.chan= {}).rendezvous= function () {
console.log("this.chan.rendezvous(), "+ (+new Date()));
};

this.chan.send= function (msgCandidate, msgBody, async) {
var r=
"31abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
if (async) {
setTimeout(function () {
console.log("this.chan.send(async===true)");
msgCandidate.dispatcher(r, 0, 0);
}, (2e3*Math.random())|0);
} else {
console.log("this.chan.send(async===false)");
msgCandidate.dispatcher(r, 0, 0);
}
};

this.chan.appendConsoleMsg= function (p) {
console.log("appendConsoleMsg: "+ p);
};
}

(Tier3Client.prototype = {}).send= function (msgBody, callback,
async) {
var chan = this.chan;
var callbackArgs = [];
var i = 0;
var msgCandidate = {
dispatcher : function (responseMsg, msgSlotId, msgSeqNum) {
callbackArgs[0] = responseMsg;
callback.apply(this, callbackArgs);
},
rendezvous : function () {
console.log("msgCandidate.rendezvous(), "+ (+new Date()));
return chan.rendezvous();
}
};
for (i=3; i<arguments.length; i++) {
callbackArgs[i - 2] = arguments;
}
return chan.send(msgCandidate, msgBody, async);
};

Tier3Client.prototype.appendConsoleMsg= function (msg) {
console.log("Tier3Client.prototype.appendConsoleMsg(), "+ (+new
Date()));
this.chan.appendConsoleMsg(msg);
};
</script>
 
L

Lew

The *what*?

<http://www.urbandictionary.com/define.php?term=interweb>
Top hit on a Google search - time: a mere one minute to find.
"A sarcastic term for the internet [sic]. Often used in the context of parody
regarding an inexperience[d], unskilled, or incoherent user."

I could infer from that that Michael means that UTF-8 is for "an
inexperience[d], unskilled, or incoherent user."

The second definition in that urban dictionary entry is funnier.
 
R

Richard Maher

Just somewhere to see it/debug.

var eventsMgr = function()
{
var AST = 0;

var setAST =
function(entryPoint,timer){
AST = setTimeout(entryPoint,timer);
empsCnt.value = AST;
^^^^^^^^^^^^^^^^^^^^

Sure ?
};

var cancelAST =
function(){
fadeSecs.value = AST;
^^^^^^^^^^^^^^^^^^^^^

Why ?
 
R

Richard Maher

Hi Jorge,

Thanks for the reply and taking the time to attempt a Java-free reproducer.
.. .


****FROM HERE****
On Jan 30, 11:01 am, "Richard Maher" <[email protected]>
wrote:
(...)

Removing the applet and the back-and-forth between Java-JS the
resulting java-less version seems to run fine:

http://jorgechamorro.com/cljs/095/

<script type="text/javascript">
function Tier3Client () {
(this.chan= {}).rendezvous= function () {
console.log("this.chan.rendezvous(), "+ (+new Date()));
};

this.chan.send= function (msgCandidate, msgBody, async) {
var r=
"31abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu
vwxyz";
if (async) {
setTimeout(function () {
console.log("this.chan.send(async===true)");
msgCandidate.dispatcher(r, 0, 0);
}, (2e3*Math.random())|0);
} else {
console.log("this.chan.send(async===false)");
msgCandidate.dispatcher(r, 0, 0);
}
};

this.chan.appendConsoleMsg= function (p) {
console.log("appendConsoleMsg: "+ p);
};
}

(Tier3Client.prototype = {}).send= function (msgBody, callback,
async) {
var chan = this.chan;
var callbackArgs = [];
var i = 0;
var msgCandidate = {
dispatcher : function (responseMsg, msgSlotId, msgSeqNum) {
callbackArgs[0] = responseMsg;
callback.apply(this, callbackArgs);
},
rendezvous : function () {
console.log("msgCandidate.rendezvous(), "+ (+new Date()));
return chan.rendezvous();
}
};
for (i=3; i<arguments.length; i++) {
callbackArgs[i - 2] = arguments;
}
return chan.send(msgCandidate, msgBody, async);
};

Tier3Client.prototype.appendConsoleMsg= function (msg) {
console.log("Tier3Client.prototype.appendConsoleMsg(), "+ (+new
Date()));
this.chan.appendConsoleMsg(msg);
};
</script>
--
Jorge.

****TO HERE****

Sadly, I'm not much further down the track (away last week) but I have
narrowed the offending line down to be in the Randomator.html file and the
positionDiv function in the EmpPicker object. Specifically it is where I
reset the innerHTML of the DIV to the new employee details: -

case "31" :
targetDiv.innerHTML =
'<table border="0" cellpadding="1px" '+
' align="center" id="empDetails"> '+
' <caption>Totally Random Employee</caption>'+
' <tr><td class="promptItem">Employee Id: </td>'
[and so on. . .]
'</table><br>';
break;

Before I start clutching at straws, and doing things like instantiating a
whole new DIV each time the timer expires, can anyone offer any
half-educated guesses here as to what might be causing the problem? Look, I
know it'd be a lot easier if I could show th JAVA code or at least a
web-link but I can't. On the useful side of the ledger though let me say
that the DOM-collision theory is backed-up by the failures appearing to
occur in pairs, i.e.: Mesages 19/20 failing followed later by 31/32.

To me it screams out "attempted multi-threaded manipulation of the DOM" but
all available evidence (inclusing anecdotal :) says otherwise. They
are/should-be exclusive updates to distinct objects.

I believe there are some quite useful LiveConnect debugging/logging options
out there that someone told me about and I've subsequently forgotten. Can
anyone help me with that? (I've set the JAVA console to "5" but that didn't
up the verbosity much)

Is there a sleep(3) function in Javascript so that I can introduce the
same/similar delay to Jorge's JAVA-free t3client.send() method as I have
with my Applet<->Server version? IOW, setTimeout(myCallback,
somethingLessThanWhatImAbout to SleepFor)?

Cheers Richard Maher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top