28 de enero de 2011

Respaldar en Windows con XCOPY

Necesité ejecutar un respaldo en una Tarea programada de Windows, usando XCOPY. He aquí el script.

@echo off

REM http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
REM /y Do not ask about overwritting
REM /q quit
REM /s copy subdirectories
REM /i create source directory
REM /e copy empty directories
REM /k retain read only attribute
REM /r copy read only files
REM /h copy hidden and system files
REM /exclude:filename1[+[filename2]][+[filename3]] : Specifies a list of files containing strings.

set SOURCEDIR=%1

set DATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

xcopy %SOURCEDIR% %SOURCEDIR%-%DATETIME% /i /s /e /k /r /h >> %SOURCEDIR%-%DATETIME%.log 2>&1

if errorlevel 5 goto diskerror
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit

:lowmemory
echo Insufficient memory to copy files or invalid drive or command-line syntax. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:abort
echo You pressed CTRL+C to end the copy operation. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:diskerror
echo Disk error. >> %SOURCEDIR%-%DATETIME%.log
goto exit

:exit

13 de enero de 2011

Checkbox de tres estados sin imágenes en HTML (estado indeterminado)

Necesitábamos un checkbox de tres estados para una sección de nuestro sitio de Internet. El checkbox debería iniciar en el tercer estado al cargar la página. También, debería poderse regresar al tercer estado usando Javascript. Además, quería que se usara el control nativo de la plataforma en la que se consultara, por lo que no podía usar imágenes. Encontré el atributo indeterminate.
Al parecer, sólo se puede acceder a este atributo mediante Javascript.

<form>
   <input id="c" type="checkbox" checked="checked"/>
</form>
<script>
   document.getElementById('c').indeterminate = true;
</script>

En la página 614 del libro Dynamic HTML: The Definitive Reference se menciona que este atributo lo reconoce Microsoft Internet Explorer versión 4 en adelante (Danny Goodman, O'Reilly Media, Third Edition edition, ISBN-10: 0596527403, ISBN-13: 978-0596527402.)


El sitio MSDN de Microsoft dice:
The indeterminate property can be used to indicate whether the user has acted on a control. For example, setting the indeterminate to true causes the check box to appear checked and dimmed, indicating an indeterminate state. The value of the indeterminate property acts independently of the values of the checked and status properties. Creating an indeterminate state is different from disabling the control. Consequently, a check box in the indeterminate state can still receive the focus. When the user clicks an indeterminate control, the indeterminate state turns off and the checked state of the check box toggles. (http://msdn.microsoft.com/en-us/library/ms533894.aspx)
El Working Draft de HTML5 más reciente hasta el día de hoy dice:
If the element's indeterminate IDL attribute is set to true, then the control's selection should be obscured as if the control was in a third, indeterminate, state. The control is never a true tri-state control, even if the element's indeterminate IDL attribute is set to true. The indeterminate IDL attribute only gives the appearance of a third state (HTML5, A vocabulary and associated APIs for HTML and XHTML, W3C Working Draft 13 January 2011).
Libros que, espero, encuentres útiles (lista automática):

11 de enero de 2011

Monitorando WebLogic 10.3.2 con JMX y JConsole

Se puede usar JMX para monitorear el uso de memoria, del CPU y qué está haciendo cada hilo de ejecución (thread) en un servidor WebLogic.


Para habilitar JMX agregué, al script de inicio de mi instancia de desarrollo, los siguientes parámetros, descritos en PerformanceEngineer.com:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Después ejecuté JConsole, que se distribuye como parte del JDK, agregando el siguiente parámetro:

service:jmx:rmi:///jndi/rmi://127.0.0.1:8888/jmxrmi

JConsole también permite monitorear el uso de los distintos tipos de memoria, condiciones de bloqueo mutuo entre threads (deadlocks), y desplegar información de los MBeans.

Por supuesto, también existe VisualVM que es un proyecto más completo para monitorear aplicaciones hechas en Java.

Espero te sirvan los siguientes libros (lista automática):

10 de enero de 2011

Cómo usar Log4J en un EJB en WebLogic 10.3.2

Para usar Log4J dentro de un EJB en WebLogic versión 10.3.2, necesitas:
  1. Copiar el archivo xml4j.jar en el directorio APP-INF\lib dentro de tu archivo .ear.
  2. Copiar el archivo de configuración de Log4J (yo usé log4j.xml) en el directorio APP-INF\classes dentro de tu archivo .ear.
Quedará una estructura como la siguiente:
  • Aplicación.ear
    • APP-INF
      • classes
        • xml4j.xml
      • lib
        • xml4j.jar
    • AplicaciónWeb.war
El directorio APP-INF\lib es propietario de WebLogic. En su lugar, en GlassFish puedes usar el tag <library-directory> del estandar Java EE 5.

Log4J es una biblioteca de Java para escribir un registro o bitácora de las actividades de un sistema de cómputo.

Libros que espero te sean útiles:

4 de enero de 2011

Cuidado con for...var en ActionScript (es diferente que en Java)

Una aplicación que hicimos con Flex, usando ActionScript 3, tenía un error. La causa fue que el ámbito (scope) de las variables en ActionScript es diferente que en Java. Al ser programadores que provenimos de Java, dimos por sentado que eran iguales.

El código en cuestión era semejante a lo siguiente:

function f () {
   for (...; ...; ...) {
      for (var j:int; ...; ...) {
         // Creíamos que j tenía un valor de cero cada vez
         // que se ejecutaba el ciclo anidado.
      }
   }
}

El compilador de ActionScript declara e inicializa sólo una vez la variable j dentro de la función f. Esto implica que, la segunda vez que se ejecuta el ciclo anidado, conserva el valor con el que terminó la ejecución anterior.

El error lo arreglamos inicializando explícitamente la variable.

function f () {
   for (...; ...; ...) {
      for (var j:int = 0; ...; ...) {
         // Ahora, j siempre inicia con un valor de cero.
      }
   }
}

Este comportamiento está descrito claramente en la documentación de ActionScript 3:

ActionScript 3.0, variables are always assigned the scope of the function or class in which they are declared. [...] ActionScript variables, unlike variables in C++ and Java, do not have block-level scope. [...] If you declare a variable inside a block of code, that variable will be available not only in that block of code, but also in any other parts of the function to which the code block belongs. —Adobe. Programming ActionScript 3.0 / ActionScript language and syntax / Variables. URL: http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_07.html#118946. Accedido: 2011-01-04. (Archivado por WebCite®)

De hecho, el compilador mueve las declaraciones de variables el inicio de la función (a esto se le llama hoisting —subimiento, levantamiento o alzamiento), haciéndolas disponibles para todo el cuerpo de la función.

Creo que seré más cuidadoso en no presuponer cómo funciona el lenguaje en el que estoy programando.